src/internet-stack/tcp-socket-impl.cc
author Antti Mäkelä <zarhan@cc.hut.fi>
Wed, 02 Jun 2010 10:44:48 -0400
changeset 6328 f03f4d82daaf
parent 6273 8d70de29d514
child 6434 ac8b4bf77e50
permissions -rw-r--r--
Bug 902 - TCP: handle out-of-order packets during connection shutdown
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
5887
50e5de0b03db add context to tcp logging
Tom Henderson <tomh@tomh.org>
parents: 5856
diff changeset
    21
#define NS_LOG_APPEND_CONTEXT                                   \
50e5de0b03db add context to tcp logging
Tom Henderson <tomh@tomh.org>
parents: 5856
diff changeset
    22
  if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; } 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
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
    24
#include "ns3/abort.h"
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include "ns3/node.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include "ns3/inet-socket-address.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
#include "ns3/log.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ns3/ipv4.h"
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    29
#include "ns3/ipv4-interface-address.h"
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
    30
#include "ns3/ipv4-route.h"
4560
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4505
diff changeset
    31
#include "ns3/ipv4-routing-protocol.h"
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
#include "ns3/simulation-singleton.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
#include "ns3/simulator.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
#include "ns3/packet.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
#include "ns3/uinteger.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
#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
    37
#include "tcp-typedefs.h"
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4505
diff changeset
    38
#include "tcp-socket-impl.h"
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4505
diff changeset
    39
#include "tcp-l4-protocol.h"
2f106fd728ab Remove static routing dependencies in code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4505
diff changeset
    40
#include "ipv4-end-point.h"
4740
34acfd7ad508 export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4627
diff changeset
    41
#include "tcp-header.h"
34acfd7ad508 export headers from internet-stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4627
diff changeset
    42
#include "rtt-estimator.h"
3131
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
#include <algorithm>
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
NS_LOG_COMPONENT_DEFINE ("TcpSocketImpl");
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),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
    m_errno (ERROR_NOTERROR),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
    m_shutdownSend (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
    m_shutdownRecv (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
    m_connected (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
    m_state (CLOSED),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
    m_closeNotified (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
    m_closeRequestNotified (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
    m_closeOnEmpty (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
    m_pendingClose (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
    m_nextTxSequence (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
    m_highTxMark (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
    m_highestRxAck (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
    m_lastRxAck (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
    m_nextRxSequence (0),
6328
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
    85
    m_finSequence (0),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    86
    m_rxAvailable (0),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    87
    m_rxBufSize (0),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
    m_pendingData (0),
4627
d132345b3e10 quiet valgrind during attribute initialization
Craig Dowell <craigdo@ee.washington.edu>
parents: 4625
diff changeset
    89
    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
    90
    m_rxWindowSize (0),
4627
d132345b3e10 quiet valgrind during attribute initialization
Craig Dowell <craigdo@ee.washington.edu>
parents: 4625
diff changeset
    91
    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
    92
    m_persistTime (Seconds(6)), //XXX hook this into attributes?
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
    m_rtt (0),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    94
    m_lastMeasuredRtt (Seconds(0.0))
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
  NS_LOG_FUNCTION (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
}
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
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
   100
  : TcpSocket(sock), //copy object::m_tid, copy socket::callbacks
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
    m_skipRetxResched (sock.m_skipRetxResched),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
    m_dupAckCount (sock.m_dupAckCount),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
    m_delAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
    m_delAckMaxCount (sock.m_delAckMaxCount),
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   105
    m_delAckTimeout (sock.m_delAckTimeout),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
    m_endPoint (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
    m_node (sock.m_node),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
    m_tcp (sock.m_tcp),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
    m_errno (sock.m_errno),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
    m_shutdownSend (sock.m_shutdownSend),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
    m_shutdownRecv (sock.m_shutdownRecv),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
    m_connected (sock.m_connected),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
    m_state (sock.m_state),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
    m_closeNotified (sock.m_closeNotified),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
    m_closeRequestNotified (sock.m_closeRequestNotified),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
    m_closeOnEmpty (sock.m_closeOnEmpty),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
    m_pendingClose (sock.m_pendingClose),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
    m_nextTxSequence (sock.m_nextTxSequence),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
    m_highTxMark (sock.m_highTxMark),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
    m_highestRxAck (sock.m_highestRxAck),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   121
    m_lastRxAck (sock.m_lastRxAck),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
    m_nextRxSequence (sock.m_nextRxSequence),
6328
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
   123
    m_finSequence (sock.m_finSequence),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   124
    m_rxAvailable (0),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   125
    m_rxBufSize (0),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
    m_pendingData (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
    m_segmentSize (sock.m_segmentSize),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
    m_rxWindowSize (sock.m_rxWindowSize),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
    m_cWnd (sock.m_cWnd),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
    m_ssThresh (sock.m_ssThresh),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
    m_initialCWnd (sock.m_initialCWnd),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   132
    m_persistTime (sock.m_persistTime),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   133
    m_rtt (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
    m_lastMeasuredRtt (Seconds(0.0)),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
    m_cnTimeout (sock.m_cnTimeout),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
    m_cnCount (sock.m_cnCount),
3251
19471cb55c9c Part of bug 198
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3250
diff changeset
   137
    m_sndBufSize (sock.m_sndBufSize),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   138
    m_rxBufMaxSize(sock.m_rxBufMaxSize)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
  NS_LOG_LOGIC("Invoked the copy constructor");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
  //copy the pending data if necessary
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
  if(sock.m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
      m_pendingData = sock.m_pendingData->Copy();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
  //copy the rtt if necessary
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
  if (sock.m_rtt)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   150
      m_rtt = sock.m_rtt->Copy();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
    }
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
   152
  //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
   153
  //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
   154
  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
   155
      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
   156
  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
   157
      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
   158
  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
   159
      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
   160
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
  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
   162
  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
   163
  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
   164
  SetRecvCallback (vPS);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
  //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
   166
  //too; this is in SYN_ACK_TX
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
TcpSocketImpl::~TcpSocketImpl ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
  NS_LOG_FUNCTION(this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
  m_node = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
  if (m_endPoint != 0)
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_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
   176
      /*
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   177
       * 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
   178
       * 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
   179
       * 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
   180
       * 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
   181
       * 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
   182
       * (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
   183
       * 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
   184
       * 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
   185
       * 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
   186
       * 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
   187
       * 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
   188
       * shutdown.
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
       */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
      m_tcp->DeAllocate (m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
      NS_ASSERT (m_endPoint == 0);
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
  m_tcp = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
  delete m_pendingData; //prevents leak
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
  m_pendingData = 0;
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   197
  CancelAllTimers();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
void
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
TcpSocketImpl::SetNode (Ptr<Node> node)
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
  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
   204
  /*
aca8363b2e21 Fix bug 579 -- TCP congestion window is not updated whent segment size chages
Craig Dowell <craigdo@ee.washington.edu>
parents: 4603
diff changeset
   205
   * 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
   206
   * 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
   207
   * 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
   208
   * 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
   209
   * 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
   210
   */
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   211
  m_cWnd = m_initialCWnd * m_segmentSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   212
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
TcpSocketImpl::SetTcp (Ptr<TcpL4Protocol> tcp)
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
  m_tcp = tcp;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
TcpSocketImpl::SetRtt (Ptr<RttEstimator> rtt)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
  m_rtt = rtt;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
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
enum Socket::SocketErrno
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
TcpSocketImpl::GetErrno (void) const
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
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
  return m_errno;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
}
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
Ptr<Node>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
TcpSocketImpl::GetNode (void) const
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
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
  return m_node;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
}
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
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
TcpSocketImpl::Destroy (void)
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
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
  m_node = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
  m_endPoint = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
  m_tcp = 0;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   247
  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
   248
                << (Simulator::Now () + 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   249
                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
   250
  CancelAllTimers();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
}
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   252
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
TcpSocketImpl::FinishBind (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
  if (m_endPoint == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   260
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   264
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
TcpSocketImpl::Bind (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
  m_endPoint = m_tcp->Allocate ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
  return FinishBind ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   272
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   273
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
TcpSocketImpl::Bind (const Address &address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
  NS_LOG_FUNCTION (this<<address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
  if (!InetSocketAddress::IsMatchingType (address))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
    {
3846
265004d6dc15 apply patch for bug 390 (SocketImpl::Bind returns something other than -1)
raj.b@gatech.edu
parents: 3818
diff changeset
   279
      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
   280
      return -1;
3131
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
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
  Ipv4Address ipv4 = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
  uint16_t port = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
  if (ipv4 == Ipv4Address::GetAny () && port == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
      m_endPoint = m_tcp->Allocate ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
  else if (ipv4 == Ipv4Address::GetAny () && port != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   291
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   292
      m_endPoint = m_tcp->Allocate (port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
  else if (ipv4 != Ipv4Address::GetAny () && port == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
      m_endPoint = m_tcp->Allocate (ipv4);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   299
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   300
  else if (ipv4 != Ipv4Address::GetAny () && port != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   302
      m_endPoint = m_tcp->Allocate (ipv4, port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   303
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   304
    }
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
  return FinishBind ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
TcpSocketImpl::ShutdownSend (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   311
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   312
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
  m_shutdownSend = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
TcpSocketImpl::ShutdownRecv (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
  NS_LOG_FUNCTION_NOARGS ();
4491
893d48fcf7f3 bug 535: UDP/TCP ShutdownRecv incorrect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   320
  m_shutdownRecv = true;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   322
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
TcpSocketImpl::Close (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   326
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   327
  NS_LOG_FUNCTION_NOARGS ();
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   328
  // 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
   329
  // 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
   330
  if (!m_bufferedData.empty())
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   331
    {
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   332
      SendRST();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   333
      return 0;
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   334
    }
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   335
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   336
  uint32_t remainingData = 0;
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   337
  if (m_pendingData)
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   338
    {
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   339
      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
   340
                                                  m_nextTxSequence);
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
  
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   343
  if (remainingData != 0)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   344
    { // App close with pending data must wait until all data transmitted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   345
      m_closeOnEmpty = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   346
      NS_LOG_LOGIC("Socket " << this << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   347
                   " deferring close, state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   348
      return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   349
    }
6328
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
   350
  m_finSequence = m_nextTxSequence + SequenceNumber (1);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   351
  Actions_t action  = ProcessEvent (APP_CLOSE);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   352
  ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   353
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   354
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   355
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   356
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   357
TcpSocketImpl::Connect (const Address & address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   358
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   359
  NS_LOG_FUNCTION (this << address);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   360
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   361
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
5984
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   362
  NS_ASSERT (ipv4 != 0);
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   363
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   364
  if (m_endPoint == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   365
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   366
      if (Bind () == -1)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   367
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   368
          NS_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   369
          return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   370
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   371
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   372
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   373
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   374
  m_endPoint->SetPeer(transport.GetIpv4 (), transport.GetPort ());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   375
  
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   376
  if (ipv4->GetRoutingProtocol () != 0)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   377
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   378
      Ipv4Header header;
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   379
      header.SetDestination (m_endPoint->GetPeerAddress());
4567
32ca321e4fe7 Bug 597: Ns-3 doesn't compile under MingWin
Faker Moatamri <faker.moatamri@sophia.inria.fr>
parents: 4560
diff changeset
   380
      Socket::SocketErrno errno_;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   381
      Ptr<Ipv4Route> route;
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   382
      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
   383
      // 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
   384
      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
   385
      if (route != 0)
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   386
        {
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   387
          NS_LOG_LOGIC ("Route exists");
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   388
          m_endPoint->SetLocalAddress (route->GetSource ());
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   389
        }
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   390
      else
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   391
        {
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   392
          NS_LOG_LOGIC ("TcpSocketImpl::Connect():  Route to " << m_endPoint->GetPeerAddress() << " 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
   393
          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
   394
          m_errno = errno_;
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   395
          return -1;
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   396
        }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   397
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   398
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
    {
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   400
      NS_FATAL_ERROR ("No Ipv4RoutingProtocol in the node");
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   401
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   402
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   403
  Actions_t action = ProcessEvent (APP_CONNECT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   404
  bool success = ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
  if (success) 
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
      return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   408
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409
  return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
}
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   411
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   412
//p here is just data, no headers
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
int 
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   414
TcpSocketImpl::Send (Ptr<Packet> p, uint32_t flags) 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
{
3250
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   416
  NS_LOG_FUNCTION (this << p);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   417
  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
   418
  {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   419
    if (p->GetSize() > GetTxAvailable ())
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   420
    {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   421
      m_errno = ERROR_MSGSIZE;
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   422
      return -1;
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 (!m_pendingData)
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_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
   427
      m_firstPendingSequence = m_nextTxSequence; // Note seq of first
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   428
    }
3250
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   429
    //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
   430
    m_pendingData->Add (p);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   431
    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
   432
        " state " << m_state);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   433
    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
   434
    NS_LOG_DEBUG(" action " << action);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   435
    if (!ProcessAction (action)) 
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   436
    {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   437
      return -1; // Failed, return zero
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   438
    }
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   439
    return p->GetSize();
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   440
  }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   441
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   442
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   443
    m_errno = ERROR_NOTCONN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   444
    return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   445
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   446
}
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
int TcpSocketImpl::DoSendTo (Ptr<Packet> p, const Address &address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   449
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   450
  NS_LOG_FUNCTION (this << p << address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   451
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   452
  Ipv4Address ipv4 = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   453
  uint16_t port = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   454
  return DoSendTo (p, ipv4, port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   455
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   456
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   457
int TcpSocketImpl::DoSendTo (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   458
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   459
  NS_LOG_FUNCTION (this << p << ipv4 << port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   460
  if (m_endPoint == 0)
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
      if (Bind () == -1)
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_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
	  return -1;
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
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
  if (m_shutdownSend)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   471
      m_errno = ERROR_SHUTDOWN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   472
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
    }
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   474
  // 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
   475
  // 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
   476
  uint32_t sentSize = p->GetSize();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   477
  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
   478
                  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
   479
  NotifyDataSent (sentSize);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   480
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   481
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   482
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   483
int 
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   484
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
   485
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
  NS_LOG_FUNCTION (this << address << p);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
  if (!m_connected)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   488
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   489
      m_errno = ERROR_NOTCONN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   490
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   491
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   492
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   493
    {
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   494
      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
   495
    }
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   498
uint32_t
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   499
TcpSocketImpl::GetTxAvailable (void) const
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
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   502
  if (m_pendingData != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   503
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   504
      uint32_t unAckedDataSize = 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   505
        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
   506
      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
   507
      return m_sndBufSize-unAckedDataSize;
3131
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
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   510
    {
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   511
      return m_sndBufSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   512
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   513
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   514
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   515
int
3772
f0d8608ab155 Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents: 3644
diff changeset
   516
TcpSocketImpl::Listen (void)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   517
{
3772
f0d8608ab155 Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents: 3644
diff changeset
   518
  NS_LOG_FUNCTION (this);
3966
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   519
  // 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
   520
  if (m_state != CLOSED)
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   521
    {
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   522
      m_errno = ERROR_INVAL;
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   523
      return -1;
b2f4788d3db7 Fix bug358; return EINVAL for inappropriate listen() call
Tom Henderson <tomh@tomh.org>
parents: 3846
diff changeset
   524
    }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   525
  Actions_t action = ProcessEvent (APP_LISTEN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   526
  ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   528
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   529
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
Ptr<Packet>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
TcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
  NS_LOG_FUNCTION_NOARGS ();
3245
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   534
  if(m_bufferedData.empty())
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   535
    {
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
   536
      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
   537
        {
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
   538
          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
   539
        }
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
   540
      //else, means nothing to read
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   541
      return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   542
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   543
  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
   544
  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
   545
  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
   546
    { // 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
   547
      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
   548
        << 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
   549
        << " 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
   550
      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
   551
      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
   552
      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
   553
        {
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   554
          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
   555
        }
3245
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   556
      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
   557
        { // 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
   558
          // 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
   559
          // 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
   560
          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
   561
          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
   562
            { // 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
   563
              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
   564
              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
   565
            }
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   566
          // 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
   567
          // 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
   568
          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
   569
        }
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   570
      m_rxAvailable -= i->second->GetSize ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   571
      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
   572
      m_bufferedData.erase (i);     // Remove from list
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   573
    }
3245
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   574
  if (out.size() == 0)
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   575
    {
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   576
      return 0;
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   577
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   578
  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
   579
  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
   580
  {
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   581
    if (outPacket->GetSize() + i->second->GetSize() <= maxSize )
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   582
    {
3248
39f736210ab2 Merge with ns-3-dev
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3246 3229
diff changeset
   583
      outPacket->AddAtEnd(i->second);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   584
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   585
    else
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   586
    {
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   587
      //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
   588
      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
   589
      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
   590
      //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
   591
      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
   592
          = 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
   593
      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
   594
      m_rxBufSize += i->second->GetSize()-avail;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   595
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   596
  }
4502
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   597
  SocketAddressTag tag;
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   598
  tag.SetAddress (InetSocketAddress (m_endPoint->GetPeerAddress(), m_endPoint->GetPeerPort()));
4502
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   599
  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
   600
  return outPacket;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   601
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   602
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   603
uint32_t
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   604
TcpSocketImpl::GetRxAvailable (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   605
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   606
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   607
  // We separately maintain this state to avoid walking the queue 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   608
  // every time this might be called
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   609
  return m_rxAvailable;
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
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   612
Ptr<Packet>
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   613
TcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
4502
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   614
                         Address &fromAddress)
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   615
{
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   616
  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
   617
  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
   618
  //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
   619
  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
   620
    {
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   621
      SocketAddressTag tag;
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   622
      bool found;
4502
07d34c0d8d18 new tags
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4472
diff changeset
   623
      found = packet->PeekPacketTag (tag);
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   624
      NS_ASSERT (found);
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   625
      fromAddress = tag.GetAddress ();
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   626
    }
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   627
  return packet;
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   628
}
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   629
3778
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   630
int
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   631
TcpSocketImpl::GetSockName (Address &address) const
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   632
{
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   633
  NS_LOG_FUNCTION_NOARGS ();
6093
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   634
  if (m_endPoint != 0)
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   635
    {
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   636
      address = InetSocketAddress (m_endPoint->GetLocalAddress (), 
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   637
                                   m_endPoint->GetLocalPort ());
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   638
    } 
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   639
  else
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   640
    {
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   641
      // It is possible to call this method on a socket without a name
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   642
      // in which case, behavior is unspecified
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   643
      address = InetSocketAddress (Ipv4Address::GetZero (), 0);
bf2ffaeca24f [bug 810] Tcp GetSockName() for unconnected sockets
Bill Roome <wdr@bell-labs.com>
parents: 5984
diff changeset
   644
    }
3778
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   645
  return 0;
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   646
}
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   647
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   648
void
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   649
TcpSocketImpl::BindToNetDevice (Ptr<NetDevice> netdevice)
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   650
{
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   651
  NS_LOG_FUNCTION (netdevice);
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   652
  Socket::BindToNetDevice (netdevice); // Includes sanity check
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   653
  if (m_endPoint == 0)
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
      if (Bind () == -1)
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
         NS_ASSERT (m_endPoint == 0);
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
      NS_ASSERT (m_endPoint != 0);
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   661
    }
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   662
  m_endPoint->BindToNetDevice (netdevice);
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   663
  return;
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   664
}
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   665
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5378
diff changeset
   666
void
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   667
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address saddr, Ipv4Address daddr, uint16_t port)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   668
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   669
  NS_LOG_DEBUG("Socket " << this << " got forward up" <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   670
               " dport " << m_endPoint->GetLocalPort() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   671
               " daddr " << m_endPoint->GetLocalAddress() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   672
               " sport " << m_endPoint->GetPeerPort() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   673
               " saddr " << m_endPoint->GetPeerAddress());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   674
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   675
  NS_LOG_FUNCTION (this << packet << saddr << daddr << port);
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   676
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   677
  Address fromAddress = InetSocketAddress (saddr, port);
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   678
  Address toAddress = InetSocketAddress (daddr, m_endPoint->GetLocalPort());
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   679
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   680
  TcpHeader tcpHeader;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   681
  packet->RemoveHeader (tcpHeader);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   682
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   683
  if (tcpHeader.GetFlags () & TcpHeader::ACK)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   684
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   685
      Time m = m_rtt->AckSeq (tcpHeader.GetAckNumber () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   686
      if (m != Seconds (0.0))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   687
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   688
          m_lastMeasuredRtt = m;
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
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   691
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   692
  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
   693
    { //persist probes end
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   694
      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
   695
      m_persistEvent.Cancel ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   696
    }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   697
  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
   698
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   699
  Events_t event = SimulationSingleton<TcpStateMachine>::Get ()->FlagsEvent (tcpHeader.GetFlags () );
6255
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   700
  // Given an ACK_RX event and FIN_WAIT_1, CLOSING, or LAST_ACK state, 
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   701
  // we have to check the sequence numbers to determine if the 
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   702
  // ACK is for the FIN
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   703
  if ((m_state == FIN_WAIT_1 || m_state == CLOSING 
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   704
                             || m_state == LAST_ACK) && event == ACK_RX)
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   705
    {
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   706
      if (tcpHeader.GetSequenceNumber () == m_nextRxSequence)
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   707
        {
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   708
          // This ACK is for the fin, change event to 
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   709
          // recognize this
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   710
          event = FIN_ACKED;
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   711
        }
ca79ce283a19 Bug 818 - TCP Socket implementation does not set ACK flag on retransmits
Josh Pelkey <jpelkey@gatech.edu>
parents: 6195
diff changeset
   712
    }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   713
  Actions_t action = ProcessEvent (event); //updates the state
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   714
  NS_LOG_DEBUG("Socket " << this << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   715
               " processing pkt action, " << action <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   716
               " current state " << m_state);
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   717
  ProcessPacketAction (action, packet, tcpHeader, fromAddress, toAddress);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   718
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   719
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   720
Actions_t TcpSocketImpl::ProcessEvent (Events_t e)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   721
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   722
  NS_LOG_FUNCTION (this << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   723
  States_t saveState = m_state;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   724
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " processing event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   725
  // 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
   726
  // class intended to be a singleton; see simulation-singleton.h
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   727
  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
   728
  NS_LOG_LOGIC ("TcpSocketImpl::ProcessEvent stateAction " << stateAction.action);
5931
894221b51957 Fix bug 747: Listening TCP socket closes on RST
Fabian Mauchle <fabian.mauchle@hsr.ch>
parents: 5887
diff changeset
   729
3131
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
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   746
    }
4625
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   747
  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
   748
    {
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   749
      NS_LOG_LOGIC ("TcpSocketImpl peer closing, send EOF to application");
6195
cc5b5294031f Bug 876 - Tcp socket does not handle ShutdownRecv correctly
Josh Pelkey <jpelkey@gatech.edu>
parents: 6163
diff changeset
   750
      if (!m_shutdownRecv)
cc5b5294031f Bug 876 - Tcp socket does not handle ShutdownRecv correctly
Josh Pelkey <jpelkey@gatech.edu>
parents: 6163
diff changeset
   751
        {
cc5b5294031f Bug 876 - Tcp socket does not handle ShutdownRecv correctly
Josh Pelkey <jpelkey@gatech.edu>
parents: 6163
diff changeset
   752
          NotifyDataRecv ();
cc5b5294031f Bug 876 - Tcp socket does not handle ShutdownRecv correctly
Josh Pelkey <jpelkey@gatech.edu>
parents: 6163
diff changeset
   753
        }
4625
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   754
    }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   755
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   756
  if (needCloseNotify && !m_closeNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   757
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   758
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   759
               << m_state << " event " << e << " closeNot " << m_closeNotified
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   760
               << " action " << stateAction.action);
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   761
      NotifyNormalClose();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   762
      m_closeNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   763
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " calling Closed from PE"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   764
              << " origState " << saveState
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   765
              << " event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   766
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   767
          << m_state << " event " << e
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   768
          << " set CloseNotif ");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   769
    }
4621
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
  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
   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
      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
   774
      /*
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   775
       * 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
   776
       * 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
   777
       * 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
   778
       * 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
   779
       * 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
   780
       * 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
   781
       * 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
   782
       */
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->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
   784
      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
   785
      m_endPoint = 0;
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   786
      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
   787
    }
bb360763b0e2 Fix 559, cpSocketImpl doesnt free endpoint quickly enough after being closed
Ewgenij Starostin <estar@cs.tu-berlin.de>
parents: 4603
diff changeset
   788
    
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   789
  return stateAction.action;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   790
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   791
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   792
void TcpSocketImpl::SendEmptyPacket (uint8_t flags)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   793
{
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   794
  NS_LOG_FUNCTION (this << (uint32_t)flags);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   795
  Ptr<Packet> p = Create<Packet> ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   796
  TcpHeader header;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   797
5984
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   798
  if (m_endPoint == 0) 
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   799
    {
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   800
      NS_LOG_WARN ("Failed to send empty packet due to null endpoint");
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   801
      return;
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   802
    }
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   803
4270
5ae6683ea586 add ACKs to naked FINs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4269
diff changeset
   804
  if (flags & TcpHeader::FIN)
5ae6683ea586 add ACKs to naked FINs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4269
diff changeset
   805
    {
5ae6683ea586 add ACKs to naked FINs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4269
diff changeset
   806
      flags |= TcpHeader::ACK;
5ae6683ea586 add ACKs to naked FINs
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4269
diff changeset
   807
    }
5984
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   808
 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   809
  header.SetFlags (flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   810
  header.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   811
  header.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   812
  header.SetSourcePort (m_endPoint->GetLocalPort ());
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   813
  header.SetDestinationPort (m_endPoint->GetPeerPort ());
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   814
  header.SetWindowSize (AdvertisedWindowSize());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   815
  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), 
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   816
    m_endPoint->GetPeerAddress (), m_boundnetdevice);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   817
  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
   818
  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
   819
  bool hasFin = flags & TcpHeader::FIN;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   820
  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
   821
  if (hasSyn)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   822
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   823
      rto = m_cnTimeout;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   824
      m_cnTimeout = m_cnTimeout + m_cnTimeout;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   825
      m_cnCount--;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   826
    }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   827
  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
   828
  //no outstanding timer
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   829
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   830
    NS_LOG_LOGIC ("Schedule retransmission timeout at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   831
          << Simulator::Now ().GetSeconds () << " to expire at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   832
          << (Simulator::Now () + rto).GetSeconds ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   833
    m_retxEvent = Simulator::Schedule (rto, &TcpSocketImpl::ReTxTimeout, this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   834
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   835
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   836
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   837
// 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
   838
void TcpSocketImpl::SendRST()
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
  SendEmptyPacket(TcpHeader::RST);
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   841
  NotifyErrorClose();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   842
  CancelAllTimers();
5984
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   843
  if (m_endPoint != 0) 
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   844
    {
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   845
      m_endPoint->SetDestroyCallback(MakeNullCallback<void>());
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   846
      m_tcp->DeAllocate (m_endPoint);
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   847
      m_endPoint = 0;
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
   848
    }
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   849
}
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   850
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
   851
  
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   852
bool TcpSocketImpl::ProcessAction (Actions_t a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   853
{ // These actions do not require a packet or any TCP Headers
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   854
  NS_LOG_FUNCTION (this << a);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   855
  switch (a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   856
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   857
    case NO_ACT:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   858
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action: NO_ACT");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   859
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   860
    case ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   861
      SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   862
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   863
    case ACK_TX_1:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   864
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   865
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   866
    case RST_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   867
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RST_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   868
      SendEmptyPacket (TcpHeader::RST);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   869
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   870
    case SYN_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   871
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   872
      // TCP SYN Flag consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   873
      // 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
   874
      // commented out for now
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   875
      // m_nextTxSequence+= 1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   876
      SendEmptyPacket (TcpHeader::SYN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   877
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   878
    case SYN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   879
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   880
      // TCP SYN Flag consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   881
      ++m_nextRxSequence;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   882
      SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
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 FIN_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   885
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   886
      SendEmptyPacket (TcpHeader::FIN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   887
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   888
    case FIN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   889
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   890
      SendEmptyPacket (TcpHeader::FIN | TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   891
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   892
    case NEW_ACK:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   893
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   894
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   895
    case NEW_SEQ_RX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   896
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
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 RETX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   899
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RETX");
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 TX_DATA:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   902
      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
   903
      SendPendingData (m_connected);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   904
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   905
    case PEER_CLOSE:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   906
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   907
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action PEER_CLOSE");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   908
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   909
    case APP_CLOSED:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   910
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_CLOSED");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   911
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   912
    case CANCEL_TM:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   913
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action CANCEL_TM");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   914
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   915
    case APP_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   916
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_NOTIFY");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   917
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   918
    case SERV_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   919
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   920
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   921
    case LAST_ACTION:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   922
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action LAST_ACTION");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   923
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   924
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   925
  return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   926
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   927
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   928
bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr<Packet> p,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   929
                                     const TcpHeader& tcpHeader,
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   930
                                     const Address& fromAddress,
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   931
                                     const Address& toAddress)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   932
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   933
  NS_LOG_FUNCTION (this << a << p  << fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   934
  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
   935
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   936
  switch (a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   937
  {
5931
894221b51957 Fix bug 747: Listening TCP socket closes on RST
Fabian Mauchle <fabian.mauchle@hsr.ch>
parents: 5887
diff changeset
   938
    case RST_TX:
894221b51957 Fix bug 747: Listening TCP socket closes on RST
Fabian Mauchle <fabian.mauchle@hsr.ch>
parents: 5887
diff changeset
   939
      {
894221b51957 Fix bug 747: Listening TCP socket closes on RST
Fabian Mauchle <fabian.mauchle@hsr.ch>
parents: 5887
diff changeset
   940
        NS_LOG_LOGIC ("TcpSocketImpl " << this << " Action RST_TX");
894221b51957 Fix bug 747: Listening TCP socket closes on RST
Fabian Mauchle <fabian.mauchle@hsr.ch>
parents: 5887
diff changeset
   941
        SendRST();
894221b51957 Fix bug 747: Listening TCP socket closes on RST
Fabian Mauchle <fabian.mauchle@hsr.ch>
parents: 5887
diff changeset
   942
        return NO_ACT;
894221b51957 Fix bug 747: Listening TCP socket closes on RST
Fabian Mauchle <fabian.mauchle@hsr.ch>
parents: 5887
diff changeset
   943
      }
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   944
    case ACK_TX:
4625
615583240b77 (bug 613) Tcp should NotifyDataRecv () when a FIN arrives
Tom Henderson <tomh@tomh.org>
parents: 4624
diff changeset
   945
      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
   946
      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
   947
      {
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   948
        ++m_nextRxSequence; //bump this to account for the FIN
6328
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
   949
        m_nextTxSequence = m_finSequence;
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   950
      }
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   951
      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
   952
      break;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   953
    case SYN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   954
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   955
      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
   956
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   957
          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
   958
          //notify the server that we got a SYN
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   959
          // If server refuses connection do nothing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   960
          if (!NotifyConnectionRequest(fromAddress)) return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   961
          // Clone the socket
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   962
          Ptr<TcpSocketImpl> newSock = Copy ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   963
          NS_LOG_LOGIC ("Cloned a TcpSocketImpl " << newSock);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   964
          //this listening socket should do nothing more
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   965
          Simulator::ScheduleNow (&TcpSocketImpl::CompleteFork, newSock,
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   966
                                  p, tcpHeader, fromAddress, toAddress);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   967
          return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   968
        }
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   969
      else
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   970
        {
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   971
          // This is the cloned endpoint
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   972
          // TCP SYN consumes one byte
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   973
          m_nextRxSequence = tcpHeader.GetSequenceNumber () 
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   974
                             + SequenceNumber (1);
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   975
          SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
   976
        }
4472
e20a31541404 src/ and utils/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4375
diff changeset
   977
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   978
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   979
    case ACK_TX_1:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   980
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   981
      // TCP SYN consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   982
      m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   983
      m_nextTxSequence = tcpHeader.GetAckNumber ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   984
      m_firstPendingSequence = m_nextTxSequence;  //bug 166
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   985
      NS_LOG_DEBUG ("TcpSocketImpl " << this << " ACK_TX_1" <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   986
                    " nextRxSeq " << m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   987
      SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   988
      if (tcpHeader.GetAckNumber () > m_highestRxAck)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   989
      {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   990
        m_highestRxAck = tcpHeader.GetAckNumber ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   991
        // 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
   992
        if (GetTxAvailable () > 0)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   993
          {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   994
            NotifySend (GetTxAvailable ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   995
          }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   996
      }
4269
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
   997
      SendPendingData (m_connected); //send acks if we are connected
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   998
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   999
    case NEW_ACK:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1000
      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
  1001
      //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
  1002
      //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
  1003
      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
  1004
        {
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1005
          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
  1006
                                 this,
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1007
                                 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
  1008
                                 p,
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1009
                                 tcpHeader,
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1010
                                 fromAddress,
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1011
                                 toAddress);
4269
78d709bebd55 Set TCP ACK whenver connection is established (closes bugs 499 and 198)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4014
diff changeset
  1012
        }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1013
      if (tcpHeader.GetAckNumber () < m_highestRxAck) //old ack, do nothing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1014
      {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1015
        break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1016
      }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1017
      if (tcpHeader.GetAckNumber () == m_highestRxAck)
3131
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_nextTxSequence)
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1020
        {
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1021
          DupAck (tcpHeader, ++m_dupAckCount);
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
        NS_ASSERT(tcpHeader.GetAckNumber ()  <= m_nextTxSequence);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1024
        //if the ack is precisely equal to the nextTxSequence
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1025
        break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1026
      }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1027
      if (tcpHeader.GetAckNumber () > m_highestRxAck)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1028
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1029
          m_dupAckCount = 0;
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
      NewAck (tcpHeader.GetAckNumber ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1032
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1033
    case NEW_SEQ_RX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1034
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_SEQ_RX");
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1035
      NewRx (p, tcpHeader, fromAddress, toAddress); // Process new data received
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1036
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1037
    case PEER_CLOSE:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1038
    {
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1039
      NS_LOG_LOGIC("Got Peer Close");
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1040
      // 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
  1041
      // out of sequence.  If so, note pending close and process
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1042
      // new sequence rx
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1043
      if (tcpHeader.GetSequenceNumber () != m_nextRxSequence)
6328
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1044
        {
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1045
          if (m_finSequence != m_nextRxSequence)
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1046
            {
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1047
              // process close later
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1048
              m_finSequence = tcpHeader.GetSequenceNumber () + SequenceNumber (p->GetSize ());
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1049
              m_pendingClose = true;
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1050
              NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1051
                << " rxseq " << tcpHeader.GetSequenceNumber () 
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1052
                << " nextRxSeq " << m_nextRxSequence);
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1053
              NewRx (p, tcpHeader, fromAddress, toAddress);
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1054
              return true;
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1055
            }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1056
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1057
      // Now we need to see if any data came with the FIN
6328
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1058
      // if so, call NewRx, unless NewRx was already called
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1059
      if (p->GetSize () != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1060
        {
6328
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1061
          if (m_finSequence != m_nextRxSequence)
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1062
            {
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1063
              NewRx (p, tcpHeader, fromAddress, toAddress);
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1064
            }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1065
        }
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
  1066
      ++m_nextRxSequence; //bump this to account for the FIN
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1067
      States_t saveState = m_state; // Used to see if app responds
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1068
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1069
          << " peer close, state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1070
      if (!m_closeRequestNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1071
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1072
          NS_LOG_LOGIC ("TCP " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1073
              << " calling AppCloseRequest");
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 5166
diff changeset
  1074
          NotifyNormalClose();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1075
          m_closeRequestNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1076
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1077
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1078
          << " peer close, state after " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1079
      if (m_state == saveState)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1080
        { // Need to ack, the application will close later
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1081
          SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1082
//               // Also need to re-tx the ack if we
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
      if (m_state == LAST_ACK)
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
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " scheduling LATO1");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1087
          m_lastAckEvent = Simulator::Schedule (m_rtt->RetransmitTimeout (),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1088
                                                &TcpSocketImpl::LastAckTimeout,this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1089
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1090
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1091
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1092
    case SERV_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1093
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SERV_NOTIFY");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1094
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1095
      m_connected = true; // ! This is bogus; fix when we clone the tcp
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1096
      m_endPoint->SetPeer (m_endPoint->GetPeerAddress(), m_endPoint->GetPeerPort());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1097
      //treat the connection orientation final ack as a newack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1098
      CommonNewAck (tcpHeader.GetAckNumber (), true);
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1099
      NotifyNewConnectionCreated (this, fromAddress);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1100
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1101
    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
  1102
      return ProcessAction (a);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1103
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1104
  return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1105
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1106
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1107
void TcpSocketImpl::CompleteFork(Ptr<Packet> p, const TcpHeader& h, const Address& fromAddress, const Address& toAddress)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1108
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1109
  // Get port and address from peer (connecting host)
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1110
  m_endPoint = m_tcp->Allocate (InetSocketAddress::ConvertFrom(toAddress).GetIpv4 (),
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1111
                                InetSocketAddress::ConvertFrom(toAddress).GetPort (),
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1112
                                InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1113
                                InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1114
  //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
  1115
  m_state = SYN_RCVD;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1116
  //equivalent to FinishBind
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1117
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1118
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5931
diff changeset
  1119
  ProcessPacketAction(SYN_ACK_TX, p, h, fromAddress, toAddress);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1120
 }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1121
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1122
void TcpSocketImpl::ConnectionSucceeded()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1123
{ // We would preferred to have scheduled an event directly to
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1124
  // NotifyConnectionSucceeded, but (sigh) these are protected
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1125
  // and we can get the address of it :(
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1126
  NotifyConnectionSucceeded();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1127
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1128
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1129
bool TcpSocketImpl::SendPendingData (bool withAck)
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
  NS_LOG_FUNCTION (this << withAck);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1132
  NS_LOG_LOGIC ("ENTERING SendPendingData");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1133
  if (!m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1134
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1135
      return false; // No data exists
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1136
    }
5984
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
  1137
  if (m_endPoint == 0)
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
  1138
    {
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
  1139
      NS_LOG_INFO ("TcpSocketImpl::SendPendingData: No endpoint; m_shutdownSend=" << m_shutdownSend);
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
  1140
      return false; // Is this the right way to handle this condition?
7a60b058e7b4 [bug 804] null pointer references in internet-stack
Bill Roome <wdr@bell-labs.com>
parents: 5971
diff changeset
  1141
    }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1142
  uint32_t nPacketsSent = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1143
  while (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_nextTxSequence))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1144
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1145
      uint32_t w = AvailableWindow ();// Get available window size
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1146
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " SendPendingData"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1147
           << " w " << w 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1148
           << " rxwin " << m_rxWindowSize
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1149
           << " cWnd " << m_cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1150
           << " segsize " << m_segmentSize
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1151
           << " nextTxSeq " << m_nextTxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1152
           << " highestRxAck " << m_highestRxAck 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1153
           << " pd->Size " << m_pendingData->Size ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1154
           << " 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
  1155
//XXX pd->Size is probably a bug, should be SizeFromSeq(...)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1156
      if (w < m_segmentSize && m_pendingData->Size () > w)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1157
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1158
          break; // No more
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1159
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1160
      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
  1161
      Ptr<Packet> p = m_pendingData->CopyFromSeq (s, m_firstPendingSequence, 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1162
        m_nextTxSequence);
3246
d734f62d4921 Change log output to be more consistent
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3245
diff changeset
  1163
      NS_LOG_LOGIC("TcpSocketImpl " << this << " SendPendingData"
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1164
                   << " txseq " << m_nextTxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1165
                   << " s " << s 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1166
                   << " datasize " << p->GetSize() );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1167
      uint8_t flags = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1168
      uint32_t sz = p->GetSize (); // Size of packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1169
      uint32_t remainingData = m_pendingData->SizeFromSeq(
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1170
          m_firstPendingSequence,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1171
          m_nextTxSequence + SequenceNumber (sz));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1172
      if (m_closeOnEmpty && (remainingData == 0))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1173
        {
6328
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
  1174
          m_finSequence = m_nextTxSequence + SequenceNumber (1 + sz);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
T&#