src/internet-stack/tcp-socket-impl.cc
author Craig Dowell <craigdo@ee.washington.edu>
Thu, 23 Oct 2008 15:59:48 -0700
changeset 3778 78c4c41557f3
parent 3772 f0d8608ab155
child 3818 080614a8e247
permissions -rw-r--r--
Liu's GetSockName patch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2007 Georgia Tech Research Corporation
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * Author: Raj Bhattacharjea <raj.b@gatech.edu>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include "ns3/node.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include "ns3/inet-socket-address.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include "ns3/log.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include "ns3/ipv4.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include "tcp-socket-impl.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
#include "tcp-l4-protocol.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ipv4-end-point.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
#include "ns3/simulation-singleton.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
#include "tcp-typedefs.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
#include "ns3/simulator.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
#include "ns3/packet.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
#include "ns3/uinteger.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
#include "ns3/trace-source-accessor.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
#include <algorithm>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
NS_LOG_COMPONENT_DEFINE ("TcpSocketImpl");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
using namespace std;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
namespace ns3 {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
NS_OBJECT_ENSURE_REGISTERED (TcpSocketImpl);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
TypeId
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
TcpSocketImpl::GetTypeId ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    49
  static TypeId tid = TypeId("ns3::TcpSocketImpl")
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
    50
    .SetParent<TcpSocket> ()
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    51
    .AddTraceSource ("CongestionWindow",
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    52
                     "The TCP connection's congestion window",
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
                     MakeTraceSourceAccessor (&TcpSocketImpl::m_cWnd))
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
  return tid;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
  TcpSocketImpl::TcpSocketImpl ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
  : m_skipRetxResched (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
    m_dupAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    61
    m_delAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    62
    m_endPoint (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    63
    m_node (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    64
    m_tcp (0),
3778
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
    65
    m_localAddress (Ipv4Address::GetZero ()),
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
    66
    m_localPort (0),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
    m_errno (ERROR_NOTERROR),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
    m_shutdownSend (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
    m_shutdownRecv (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
    m_connected (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
    m_state (CLOSED),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
    m_closeNotified (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
    m_closeRequestNotified (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
    m_closeOnEmpty (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
    m_pendingClose (false),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
    m_nextTxSequence (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
    m_highTxMark (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
    m_highestRxAck (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
    m_lastRxAck (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
    m_nextRxSequence (0),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    81
    m_rxAvailable (0),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    82
    m_rxBufSize (0),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
    m_pendingData (0),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    84
    m_rxWindowSize (0),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    85
    m_persistTime (Seconds(6)), //XXX hook this into attributes?
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
    m_rtt (0),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
    87
    m_lastMeasuredRtt (Seconds(0.0))
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
  NS_LOG_FUNCTION (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
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
    93
  : TcpSocket(sock), //copy object::m_tid, copy socket::callbacks
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
    m_skipRetxResched (sock.m_skipRetxResched),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
    m_dupAckCount (sock.m_dupAckCount),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
    m_delAckCount (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    97
    m_delAckMaxCount (sock.m_delAckMaxCount),
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
    98
    m_delAckTimeout (sock.m_delAckTimeout),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
    m_endPoint (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
    m_node (sock.m_node),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
    m_tcp (sock.m_tcp),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
    m_remoteAddress (sock.m_remoteAddress),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
    m_remotePort (sock.m_remotePort),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   104
    m_localAddress (sock.m_localAddress),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
    m_localPort (sock.m_localPort),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
    m_errno (sock.m_errno),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
    m_shutdownSend (sock.m_shutdownSend),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
    m_shutdownRecv (sock.m_shutdownRecv),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
    m_connected (sock.m_connected),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
    m_state (sock.m_state),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
    m_closeNotified (sock.m_closeNotified),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
    m_closeRequestNotified (sock.m_closeRequestNotified),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
    m_closeOnEmpty (sock.m_closeOnEmpty),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
    m_pendingClose (sock.m_pendingClose),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
    m_nextTxSequence (sock.m_nextTxSequence),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
    m_highTxMark (sock.m_highTxMark),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   117
    m_highestRxAck (sock.m_highestRxAck),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   118
    m_lastRxAck (sock.m_lastRxAck),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
    m_nextRxSequence (sock.m_nextRxSequence),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   120
    m_rxAvailable (0),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   121
    m_rxBufSize (0),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
    m_pendingData (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
    m_segmentSize (sock.m_segmentSize),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
    m_rxWindowSize (sock.m_rxWindowSize),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
    m_cWnd (sock.m_cWnd),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
    m_ssThresh (sock.m_ssThresh),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
    m_initialCWnd (sock.m_initialCWnd),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   128
    m_persistTime (sock.m_persistTime),
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
    m_rtt (0),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   130
    m_lastMeasuredRtt (Seconds(0.0)),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   131
    m_cnTimeout (sock.m_cnTimeout),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
    m_cnCount (sock.m_cnCount),
3251
19471cb55c9c Part of bug 198
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3250
diff changeset
   133
    m_sndBufSize (sock.m_sndBufSize),
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   134
    m_rxBufMaxSize(sock.m_rxBufMaxSize)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   136
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
  NS_LOG_LOGIC("Invoked the copy constructor");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
  //copy the pending data if necessary
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   139
  if(sock.m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   140
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
      m_pendingData = sock.m_pendingData->Copy();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
  //copy the rtt if necessary
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
  if (sock.m_rtt)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
      m_rtt = sock.m_rtt->Copy();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
    }
3475
8523b98f949c Make PacketSink multitasking for TCP (closes bug 244)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
   148
  //null out the socket base class recvcallback,
8523b98f949c Make PacketSink multitasking for TCP (closes bug 244)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
   149
  //make user of the socket register this explicitly
8523b98f949c Make PacketSink multitasking for TCP (closes bug 244)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
   150
  SetRecvCallback (MakeNullCallback<void, Ptr<Socket> > () );
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   151
  //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
   152
  //too; this is in SYN_ACK_TX
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
TcpSocketImpl::~TcpSocketImpl ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
  NS_LOG_FUNCTION(this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
  m_node = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   159
  if (m_endPoint != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   160
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   161
      NS_ASSERT (m_tcp != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   162
      /**
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   163
       * Note that this piece of code is a bit tricky:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   164
       * when DeAllocate is called, it will call into
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   165
       * Ipv4EndPointDemux::Deallocate which triggers
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
       * a delete of the associated endPoint which triggers
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
       * in turn a call to the method ::Destroy below
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   168
       * will will zero the m_endPoint field.
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
       */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
      m_tcp->DeAllocate (m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
      NS_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   173
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   174
  m_tcp = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
  delete m_pendingData; //prevents leak
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
  m_pendingData = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   177
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
void
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
TcpSocketImpl::SetNode (Ptr<Node> node)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   182
  m_node = node;
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   183
  // Initialize some variables 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   184
  m_cWnd = m_initialCWnd * m_segmentSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   188
TcpSocketImpl::SetTcp (Ptr<TcpL4Protocol> tcp)
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
  m_tcp = tcp;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
TcpSocketImpl::SetRtt (Ptr<RttEstimator> rtt)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   194
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   195
  m_rtt = rtt;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
enum Socket::SocketErrno
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
TcpSocketImpl::GetErrno (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   202
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   203
  return m_errno;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   205
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   206
Ptr<Node>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   207
TcpSocketImpl::GetNode (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   208
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   209
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   210
  return m_node;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   211
}
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
void 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   214
TcpSocketImpl::Destroy (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   215
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   216
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
  m_node = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
  m_endPoint = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
  m_tcp = 0;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   220
  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
   221
                << (Simulator::Now () + 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   222
                Simulator::GetDelayLeft (m_retxEvent)).GetSeconds());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   223
  m_retxEvent.Cancel ();
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
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
TcpSocketImpl::FinishBind (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   228
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   229
  if (m_endPoint == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   230
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   231
      return -1;
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
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
  m_localAddress = m_endPoint->GetLocalAddress ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
  m_localPort = m_endPoint->GetLocalPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
  return 0;
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
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   241
TcpSocketImpl::Bind (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_endPoint = m_tcp->Allocate ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
  return FinishBind ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
TcpSocketImpl::Bind (const Address &address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   250
  NS_LOG_FUNCTION (this<<address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   251
  if (!InetSocketAddress::IsMatchingType (address))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   252
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   253
      return ERROR_INVAL;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   254
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   255
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   256
  Ipv4Address ipv4 = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   257
  uint16_t port = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   258
  if (ipv4 == Ipv4Address::GetAny () && port == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   259
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   260
      m_endPoint = m_tcp->Allocate ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   261
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   262
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   263
  else if (ipv4 == Ipv4Address::GetAny () && port != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   264
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   265
      m_endPoint = m_tcp->Allocate (port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   266
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   267
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   268
  else if (ipv4 != Ipv4Address::GetAny () && port == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   269
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   270
      m_endPoint = m_tcp->Allocate (ipv4);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   271
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
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
  else if (ipv4 != Ipv4Address::GetAny () && port != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   274
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   275
      m_endPoint = m_tcp->Allocate (ipv4, port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   276
      NS_LOG_LOGIC ("TcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   277
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   278
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   279
  return FinishBind ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   280
}
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
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   283
TcpSocketImpl::ShutdownSend (void)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   285
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   286
  m_shutdownSend = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   287
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   288
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   289
int 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   290
TcpSocketImpl::ShutdownRecv (void)
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
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   293
  m_shutdownRecv = false;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   294
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   295
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   296
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   297
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   298
TcpSocketImpl::Close (void)
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
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   301
  if (m_state == CLOSED) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   302
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   303
      return -1;
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
  if (m_pendingData && m_pendingData->Size() != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   306
    { // App close with pending data must wait until all data transmitted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   307
      m_closeOnEmpty = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   308
      NS_LOG_LOGIC("Socket " << this << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   309
                   " deferring close, state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   310
      return 0;
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   313
  Actions_t action  = ProcessEvent (APP_CLOSE);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   314
  ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   315
  ShutdownSend ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   316
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   317
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   318
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   319
int
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   320
TcpSocketImpl::Connect (const Address & address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   321
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   322
  NS_LOG_FUNCTION (this << address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   323
  if (m_endPoint == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   324
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   325
      if (Bind () == -1)
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_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   328
          return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   329
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   330
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   331
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   332
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   333
  m_remoteAddress = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   334
  m_remotePort = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   335
  
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   336
  uint32_t localIfIndex;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   337
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   338
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   339
  if (ipv4->GetIfIndexForDestination (m_remoteAddress, localIfIndex))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   340
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   341
      m_endPoint->SetLocalAddress (ipv4->GetAddress (localIfIndex));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   342
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   343
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   344
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   345
      m_errno = ERROR_NOROUTETOHOST;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   346
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   347
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   348
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   349
  Actions_t action = ProcessEvent (APP_CONNECT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   350
  bool success = ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   351
  if (success) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   352
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   353
      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
  return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   356
}
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   357
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   358
//p here is just data, no headers
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   359
int 
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   360
TcpSocketImpl::Send (Ptr<Packet> p, uint32_t flags) 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   361
{
3250
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   362
  NS_LOG_FUNCTION (this << p);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   363
  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
   364
  {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   365
    if (p->GetSize() > GetTxAvailable ())
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   366
    {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   367
      m_errno = ERROR_MSGSIZE;
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   368
      return -1;
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   369
    }
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   370
    if (!m_pendingData)
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   371
    {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   372
      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
   373
      m_firstPendingSequence = m_nextTxSequence; // Note seq of first
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   374
    }
3250
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   375
    //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
   376
    m_pendingData->Add (p);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   377
    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
   378
        " state " << m_state);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   379
    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
   380
    NS_LOG_DEBUG(" action " << action);
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   381
    if (!ProcessAction (action)) 
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   382
    {
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   383
      return -1; // Failed, return zero
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   384
    }
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   385
    return p->GetSize();
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3248
diff changeset
   386
  }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   387
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   388
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   389
    m_errno = ERROR_NOTCONN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   390
    return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   391
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   392
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   393
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   394
int TcpSocketImpl::DoSendTo (Ptr<Packet> p, const Address &address)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   395
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   396
  NS_LOG_FUNCTION (this << p << address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   397
  InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   398
  Ipv4Address ipv4 = transport.GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
  uint16_t port = transport.GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   400
  return DoSendTo (p, ipv4, port);
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
int TcpSocketImpl::DoSendTo (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   404
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   405
  NS_LOG_FUNCTION (this << p << ipv4 << port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   406
  if (m_endPoint == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   407
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   408
      if (Bind () == -1)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   409
	{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   410
          NS_ASSERT (m_endPoint == 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   411
	  return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   412
	}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
      NS_ASSERT (m_endPoint != 0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   414
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   415
  if (m_shutdownSend)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   416
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   417
      m_errno = ERROR_SHUTDOWN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   418
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   419
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   420
  m_tcp->Send (p, m_endPoint->GetLocalAddress (), ipv4,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   421
                  m_endPoint->GetLocalPort (), port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   422
  NotifyDataSent (p->GetSize ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   423
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   424
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   425
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   426
int 
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   427
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
   428
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   429
  NS_LOG_FUNCTION (this << address << p);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   430
  if (!m_connected)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   431
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   432
      m_errno = ERROR_NOTCONN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   433
      return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   434
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   435
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   436
    {
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   437
      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
   438
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   439
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   440
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   441
uint32_t
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   442
TcpSocketImpl::GetTxAvailable (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   443
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   444
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   445
  if (m_pendingData != 0)
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
      uint32_t unAckedDataSize = 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   448
        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
   449
      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
   450
      return m_sndBufSize-unAckedDataSize;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   451
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   452
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   453
    {
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   454
      return m_sndBufSize;
3131
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   458
int
3772
f0d8608ab155 Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents: 3644
diff changeset
   459
TcpSocketImpl::Listen (void)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   460
{
3772
f0d8608ab155 Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents: 3644
diff changeset
   461
  NS_LOG_FUNCTION (this);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   462
  Actions_t action = ProcessEvent (APP_LISTEN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   463
  ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   464
  return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   465
}
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
Ptr<Packet>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   468
TcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   469
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   470
  NS_LOG_FUNCTION_NOARGS ();
3245
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   471
  if(m_bufferedData.empty())
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   472
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   473
      return 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   474
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   475
  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
   476
  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
   477
  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
   478
    { // 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
   479
      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
   480
        << 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
   481
        << " 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
   482
      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
   483
      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
   484
      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
   485
        {
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   486
          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
   487
        }
3245
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   488
      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
   489
        { // 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
   490
          // 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
   491
          // 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
   492
          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
   493
          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
   494
            { // 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
   495
              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
   496
              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
   497
            }
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   498
          // 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
   499
          // 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
   500
          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
   501
        }
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   502
      m_rxAvailable -= i->second->GetSize ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   503
      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
   504
      m_bufferedData.erase (i);     // Remove from list
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   505
    }
3245
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   506
  if (out.size() == 0)
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   507
    {
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   508
      return 0;
ad57fb768f3a Fix up recv buffer stuff some more
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   509
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   510
  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
   511
  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
   512
  {
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   513
    if (outPacket->GetSize() + i->second->GetSize() <= maxSize )
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   514
    {
3248
39f736210ab2 Merge with ns-3-dev
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3246 3229
diff changeset
   515
      outPacket->AddAtEnd(i->second);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   516
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   517
    else
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   518
    {
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   519
      //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
   520
      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
   521
      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
   522
      //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
   523
      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
   524
          = 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
   525
      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
   526
      m_rxBufSize += i->second->GetSize()-avail;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   527
    }
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   528
  }
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   529
  return outPacket;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   530
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   531
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   532
uint32_t
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   533
TcpSocketImpl::GetRxAvailable (void) const
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   534
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   535
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   536
  // We separately maintain this state to avoid walking the queue 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   537
  // every time this might be called
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   538
  return m_rxAvailable;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   539
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   540
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   541
Ptr<Packet>
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   542
TcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   543
  Address &fromAddress)
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   544
{
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   545
  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
   546
  Ptr<Packet> packet = Recv (maxSize, flags);
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   547
  if (packet != 0)
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   548
    {
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   549
      SocketAddressTag tag;
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   550
      bool found;
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   551
      found = packet->FindFirstMatchingTag (tag);
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   552
      NS_ASSERT (found);
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   553
      fromAddress = tag.GetAddress ();
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   554
    }
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   555
  return packet;
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   556
}
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
   557
3778
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   558
int
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   559
TcpSocketImpl::GetSockName (Address &address) const
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   560
{
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   561
  NS_LOG_FUNCTION_NOARGS ();
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   562
  address = InetSocketAddress(m_localAddress, m_localPort);
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   563
  return 0;
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   564
}
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
   565
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   566
void
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   567
TcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Address ipv4, uint16_t port)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   568
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   569
  NS_LOG_DEBUG("Socket " << this << " got forward up" <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   570
               " dport " << m_endPoint->GetLocalPort() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   571
               " daddr " << m_endPoint->GetLocalAddress() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   572
               " sport " << m_endPoint->GetPeerPort() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   573
               " saddr " << m_endPoint->GetPeerAddress());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   574
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   575
  NS_LOG_FUNCTION (this << packet << ipv4 << port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   576
  if (m_shutdownRecv)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   577
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   578
      return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   579
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   580
  TcpHeader tcpHeader;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   581
  packet->RemoveHeader (tcpHeader);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   582
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   583
  if (tcpHeader.GetFlags () & TcpHeader::ACK)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   584
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   585
      Time m = m_rtt->AckSeq (tcpHeader.GetAckNumber () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   586
      if (m != Seconds (0.0))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   587
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   588
          m_lastMeasuredRtt = m;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   589
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   590
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   591
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   592
  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
   593
    { //persist probes end
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   594
      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
   595
      m_persistEvent.Cancel ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   596
    }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   597
  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
   598
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   599
  Events_t event = SimulationSingleton<TcpStateMachine>::Get ()->FlagsEvent (tcpHeader.GetFlags () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   600
  Actions_t action = ProcessEvent (event); //updates the state
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   601
  Address address = InetSocketAddress (ipv4, port);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   602
  NS_LOG_DEBUG("Socket " << this << 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   603
               " processing pkt action, " << action <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   604
               " current state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   605
  ProcessPacketAction (action, packet, tcpHeader, address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   606
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   607
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   608
Actions_t TcpSocketImpl::ProcessEvent (Events_t e)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   609
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   610
  NS_LOG_FUNCTION (this << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   611
  States_t saveState = m_state;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   612
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " processing event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   613
  // 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
   614
  // class intended to be a singleton; see simulation-singleton.h
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   615
  SA stateAction = SimulationSingleton<TcpStateMachine>::Get ()->Lookup (m_state,e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   616
  // debug
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   617
  if (stateAction.action == RST_TX)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   618
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   619
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " sending RST from state "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   620
              << saveState << " event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   621
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   622
  bool needCloseNotify = (stateAction.state == CLOSED && m_state != CLOSED 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   623
    && e != TIMEOUT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   624
  m_state = stateAction.state;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   625
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " moved from state " << saveState 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   626
    << " to state " <<m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   627
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " pendingData " << m_pendingData);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   628
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   629
  //extra event logic is here for RX events
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   630
  //e = SYN_ACK_RX
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   631
  if (saveState == SYN_SENT && m_state == ESTABLISHED)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   632
    // this means the application side has completed its portion of 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   633
    // the handshaking
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   634
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   635
      Simulator::ScheduleNow(&TcpSocketImpl::ConnectionSucceeded, this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   636
      //NotifyConnectionSucceeded ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   637
      m_connected = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   638
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   639
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   640
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   641
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   642
  if (needCloseNotify && !m_closeNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   643
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   644
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   645
               << m_state << " event " << e << " closeNot " << m_closeNotified
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   646
               << " action " << stateAction.action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   647
      m_closeNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   648
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " calling Closed from PE"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   649
              << " origState " << saveState
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   650
              << " event " << e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   651
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " transition to CLOSED from "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   652
          << m_state << " event " << e
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   653
          << " set CloseNotif ");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   654
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   655
  return stateAction.action;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   656
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   657
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   658
void TcpSocketImpl::SendEmptyPacket (uint8_t flags)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   659
{
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   660
  NS_LOG_FUNCTION (this << (uint32_t)flags);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   661
  Ptr<Packet> p = Create<Packet> ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   662
  TcpHeader header;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   663
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   664
  header.SetFlags (flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   665
  header.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   666
  header.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   667
  header.SetSourcePort (m_endPoint->GetLocalPort ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   668
  header.SetDestinationPort (m_remotePort);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   669
  header.SetWindowSize (AdvertisedWindowSize());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   670
  m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (), 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   671
    m_remoteAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   672
  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
   673
  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
   674
  bool hasFin = flags & TcpHeader::FIN;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   675
  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
   676
  if (hasSyn)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   677
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   678
      rto = m_cnTimeout;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   679
      m_cnTimeout = m_cnTimeout + m_cnTimeout;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   680
      m_cnCount--;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   681
    }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   682
  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
   683
  //no outstanding timer
3131
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
    NS_LOG_LOGIC ("Schedule retransmission timeout at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   686
          << Simulator::Now ().GetSeconds () << " to expire at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   687
          << (Simulator::Now () + rto).GetSeconds ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   688
    m_retxEvent = Simulator::Schedule (rto, &TcpSocketImpl::ReTxTimeout, this);
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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   692
bool TcpSocketImpl::ProcessAction (Actions_t a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   693
{ // These actions do not require a packet or any TCP Headers
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   694
  NS_LOG_FUNCTION (this << a);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   695
  switch (a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   696
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   697
    case NO_ACT:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   698
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action: NO_ACT");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   699
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   700
    case ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   701
      SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   702
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   703
    case ACK_TX_1:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   704
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   705
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   706
    case RST_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   707
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RST_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   708
      SendEmptyPacket (TcpHeader::RST);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   709
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   710
    case SYN_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   711
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   712
      // TCP SYN Flag consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   713
      // 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
   714
      // commented out for now
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   715
      // m_nextTxSequence+= 1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   716
      SendEmptyPacket (TcpHeader::SYN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   717
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   718
    case SYN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   719
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   720
      // TCP SYN Flag consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   721
      ++m_nextRxSequence;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   722
      SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   723
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   724
    case FIN_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   725
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   726
      SendEmptyPacket (TcpHeader::FIN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   727
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   728
    case FIN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   729
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action FIN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   730
      SendEmptyPacket (TcpHeader::FIN | TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   731
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   732
    case NEW_ACK:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   733
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   734
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   735
    case NEW_SEQ_RX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   736
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   737
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   738
    case RETX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   739
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action RETX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   740
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   741
    case TX_DATA:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   742
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action TX_DATA");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   743
      SendPendingData ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   744
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   745
    case PEER_CLOSE:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   746
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   747
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action PEER_CLOSE");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   748
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   749
    case APP_CLOSED:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   750
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_CLOSED");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   751
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   752
    case CANCEL_TM:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   753
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action CANCEL_TM");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   754
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   755
    case APP_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   756
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action APP_NOTIFY");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   757
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   758
    case SERV_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   759
      NS_ASSERT (false); // This should be processed in ProcessPacketAction
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   760
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   761
    case LAST_ACTION:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   762
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action LAST_ACTION");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   763
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   764
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   765
  return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   766
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   767
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   768
bool TcpSocketImpl::ProcessPacketAction (Actions_t a, Ptr<Packet> p,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   769
                                     const TcpHeader& tcpHeader,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   770
                                     const Address& fromAddress)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   771
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   772
  NS_LOG_FUNCTION (this << a << p  << fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   773
  uint32_t localIfIndex;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   774
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   775
  switch (a)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   776
  {
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   777
    case ACK_TX:
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   778
      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
   779
      {
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   780
        ++m_nextRxSequence; //bump this to account for the FIN
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   781
      }
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   782
      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
   783
      break;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   784
    case SYN_ACK_TX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   785
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SYN_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   786
//      m_remotePort = InetSocketAddress::ConvertFrom (fromAddress).GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   787
//      m_remoteAddress = InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   788
//       if (ipv4->GetIfIndexForDestination (m_remoteAddress, localIfIndex))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   789
//         {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   790
//           m_localAddress = ipv4->GetAddress (localIfIndex);
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
      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
   793
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   794
          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
   795
          //notify the server that we got a SYN
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   796
          // If server refuses connection do nothing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   797
          if (!NotifyConnectionRequest(fromAddress)) return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   798
          // Clone the socket
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   799
          Ptr<TcpSocketImpl> newSock = Copy ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   800
          NS_LOG_LOGIC ("Cloned a TcpSocketImpl " << newSock);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   801
          //this listening socket should do nothing more
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   802
          Simulator::ScheduleNow (&TcpSocketImpl::CompleteFork, newSock,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   803
                                  p, tcpHeader,fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   804
          return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   805
        }
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   806
      // This is the cloned endpoint
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   807
      NS_ASSERT (m_state == SYN_RCVD);
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   808
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   809
      if (ipv4->GetIfIndexForDestination (m_remoteAddress, localIfIndex))
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   810
        {
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   811
          m_localAddress = ipv4->GetAddress (localIfIndex);
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   812
          m_endPoint->SetLocalAddress (m_localAddress);
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   813
          // Leave local addr in the portmap to any, as the path from
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   814
          // remote can change and packets can arrive on different interfaces
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   815
          //m_endPoint->SetLocalAddress (Ipv4Address::GetAny());
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   816
        }
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   817
      // TCP SYN consumes one byte
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   818
      m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   819
      SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   820
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   821
    case ACK_TX_1:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   822
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action ACK_TX_1");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   823
      // TCP SYN consumes one byte
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   824
      m_nextRxSequence = tcpHeader.GetSequenceNumber() + SequenceNumber(1);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   825
      m_nextTxSequence = tcpHeader.GetAckNumber ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   826
      m_firstPendingSequence = m_nextTxSequence;  //bug 166
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   827
      NS_LOG_DEBUG ("TcpSocketImpl " << this << " ACK_TX_1" <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   828
                    " nextRxSeq " << m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   829
      SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   830
      if (tcpHeader.GetAckNumber () > m_highestRxAck)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   831
      {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   832
        m_highestRxAck = tcpHeader.GetAckNumber ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   833
        // 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
   834
        if (GetTxAvailable () > 0)
3131
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
            NotifySend (GetTxAvailable ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   837
          }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   838
      }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   839
      SendPendingData ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   840
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   841
    case NEW_ACK:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   842
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_ACK_TX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   843
      if (tcpHeader.GetAckNumber () < m_highestRxAck) //old ack, do nothing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   844
      {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   845
        break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   846
      }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   847
      if (tcpHeader.GetAckNumber () == m_highestRxAck)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   848
      {
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   849
        if (tcpHeader.GetAckNumber ()  < m_nextTxSequence)
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   850
        {
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   851
          DupAck (tcpHeader, ++m_dupAckCount);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   852
        }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   853
        NS_ASSERT(tcpHeader.GetAckNumber ()  <= m_nextTxSequence);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   854
        //if the ack is precisely equal to the nextTxSequence
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   855
        break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   856
      }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
   857
      if (tcpHeader.GetAckNumber () > m_highestRxAck)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   858
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   859
          m_dupAckCount = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   860
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   861
      NewAck (tcpHeader.GetAckNumber ());
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 NEW_SEQ_RX:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   864
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action NEW_SEQ_RX");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   865
      NewRx (p, tcpHeader, fromAddress); // Process new data received
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   866
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   867
    case PEER_CLOSE:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   868
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   869
      // 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
   870
      // out of sequence.  If so, note pending close and process
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   871
      // new sequence rx
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   872
      if (tcpHeader.GetSequenceNumber () != m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   873
        { // process close later
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   874
          m_pendingClose = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   875
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " setting pendingClose" 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   876
            << " rxseq " << tcpHeader.GetSequenceNumber () 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   877
            << " nextRxSeq " << m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   878
          NewRx (p, tcpHeader, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   879
          return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   880
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   881
      // Now we need to see if any data came with the FIN
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   882
      // if so, call NewRx
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   883
      if (p->GetSize () != 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   884
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   885
          NewRx (p, tcpHeader, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   886
        }
3643
7afa66c2b291 Fix TCP closedown FINs, and remove broken tcp-erros example (bug 242)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3588
diff changeset
   887
      ++m_nextRxSequence; //bump this to account for the FIN
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   888
      States_t saveState = m_state; // Used to see if app responds
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   889
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   890
          << " peer close, state " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   891
      if (!m_closeRequestNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   892
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   893
          NS_LOG_LOGIC ("TCP " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   894
              << " calling AppCloseRequest");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   895
          m_closeRequestNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   896
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   897
      NS_LOG_LOGIC ("TcpSocketImpl " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   898
          << " peer close, state after " << m_state);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   899
      if (m_state == saveState)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   900
        { // Need to ack, the application will close later
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   901
          SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   902
//               // Also need to re-tx the ack if we
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   903
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   904
      if (m_state == LAST_ACK)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   905
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   906
          NS_LOG_LOGIC ("TcpSocketImpl " << this << " scheduling LATO1");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   907
          m_lastAckEvent = Simulator::Schedule (m_rtt->RetransmitTimeout (),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   908
                                                &TcpSocketImpl::LastAckTimeout,this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   909
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   910
      break;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   911
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   912
    case SERV_NOTIFY:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   913
      NS_LOG_LOGIC ("TcpSocketImpl " << this <<" Action SERV_NOTIFY");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   914
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " Connected!");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   915
      m_connected = true; // ! This is bogus; fix when we clone the tcp
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   916
      m_endPoint->SetPeer (m_remoteAddress, m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   917
      //treat the connection orientation final ack as a newack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   918
      CommonNewAck (tcpHeader.GetAckNumber (), true);
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
   919
      NotifyNewConnectionCreated (this, fromAddress);
3131
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
    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
   922
      return ProcessAction (a);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   923
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   924
  return true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   925
}
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
void TcpSocketImpl::CompleteFork(Ptr<Packet> p, const TcpHeader& h, const Address& fromAddress)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   928
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   929
  // Get port and address from peer (connecting host)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   930
  m_remotePort = InetSocketAddress::ConvertFrom (fromAddress).GetPort ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   931
  m_remoteAddress = InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   932
  m_endPoint = m_tcp->Allocate (m_localAddress,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   933
                                m_localPort,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   934
                                m_remoteAddress,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   935
                                m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   936
  //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
   937
  m_state = SYN_RCVD;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   938
  //equivalent to FinishBind
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   939
  m_endPoint->SetRxCallback (MakeCallback (&TcpSocketImpl::ForwardUp, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   940
  m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketImpl::Destroy, Ptr<TcpSocketImpl>(this)));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   941
  ProcessPacketAction(SYN_ACK_TX, p, h, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   942
 }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   943
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   944
void TcpSocketImpl::ConnectionSucceeded()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   945
{ // We would preferred to have scheduled an event directly to
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   946
  // NotifyConnectionSucceeded, but (sigh) these are protected
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   947
  // and we can get the address of it :(
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   948
  NotifyConnectionSucceeded();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   949
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   950
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   951
bool TcpSocketImpl::SendPendingData (bool withAck)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   952
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   953
  NS_LOG_FUNCTION (this << withAck);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   954
  NS_LOG_LOGIC ("ENTERING SendPendingData");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   955
  if (!m_pendingData)
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
      return false; // No data exists
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   958
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   959
  uint32_t nPacketsSent = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   960
  while (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_nextTxSequence))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   961
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   962
      uint32_t w = AvailableWindow ();// Get available window size
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   963
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " SendPendingData"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   964
           << " w " << w 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   965
           << " rxwin " << m_rxWindowSize
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   966
           << " cWnd " << m_cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   967
           << " segsize " << m_segmentSize
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   968
           << " nextTxSeq " << m_nextTxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   969
           << " highestRxAck " << m_highestRxAck 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   970
           << " pd->Size " << m_pendingData->Size ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   971
           << " 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
   972
//XXX pd->Size is probably a bug, should be SizeFromSeq(...)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   973
      if (w < m_segmentSize && m_pendingData->Size () > w)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   974
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   975
          break; // No more
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   976
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   977
      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
   978
      Ptr<Packet> p = m_pendingData->CopyFromSeq (s, m_firstPendingSequence, 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   979
        m_nextTxSequence);
3246
d734f62d4921 Change log output to be more consistent
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3245
diff changeset
   980
      NS_LOG_LOGIC("TcpSocketImpl " << this << " SendPendingData"
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   981
                   << " txseq " << m_nextTxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   982
                   << " s " << s 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   983
                   << " datasize " << p->GetSize() );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   984
      uint8_t flags = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   985
      if (withAck)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   986
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   987
          flags |= TcpHeader::ACK;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   988
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   989
      uint32_t sz = p->GetSize (); // Size of packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   990
      uint32_t remainingData = m_pendingData->SizeFromSeq(
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   991
          m_firstPendingSequence,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   992
          m_nextTxSequence + SequenceNumber (sz));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   993
      if (m_closeOnEmpty && (remainingData == 0))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   994
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   995
          flags = TcpHeader::FIN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   996
          m_state = FIN_WAIT_1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   997
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   998
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   999
      TcpHeader header;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1000
      header.SetFlags (flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1001
      header.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1002
      header.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1003
      header.SetSourcePort (m_endPoint->GetLocalPort());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1004
      header.SetDestinationPort (m_remotePort);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1005
      header.SetWindowSize (AdvertisedWindowSize());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1006
      if (m_shutdownSend)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1007
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1008
          m_errno = ERROR_SHUTDOWN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1009
          return -1;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1010
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1011
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1012
      
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1013
      if (m_retxEvent.IsExpired () ) //go ahead and schedule the retransmit
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
            Time rto = m_rtt->RetransmitTimeout (); 
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1016
            NS_LOG_LOGIC (this<<" SendPendingData Schedule ReTxTimeout at time " << 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1017
              Simulator::Now ().GetSeconds () << " to expire at time " <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1018
              (Simulator::Now () + rto).GetSeconds () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1019
          m_retxEvent = Simulator::Schedule (rto,&TcpSocketImpl::ReTxTimeout,this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1020
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1021
      NS_LOG_LOGIC ("About to send a packet with flags: " << flags);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1022
      m_tcp->SendPacket (p, header,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1023
                         m_endPoint->GetLocalAddress (),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1024
                         m_remoteAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1025
      m_rtt->SentSeq(m_nextTxSequence, sz);       // notify the RTT
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1026
      // Notify the application
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1027
      Simulator::ScheduleNow(&TcpSocketImpl::NotifyDataSent, this, p->GetSize ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1028
      nPacketsSent++;                             // Count sent this loop
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1029
      m_nextTxSequence += sz;                     // Advance next tx sequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1030
      // Note the high water mark
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1031
      m_highTxMark = std::max (m_nextTxSequence, m_highTxMark);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1032
    }
3246
d734f62d4921 Change log output to be more consistent
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3245
diff changeset
  1033
    NS_LOG_LOGIC ("SendPendingData Sent "<<nPacketsSent<<" packets");
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1034
  NS_LOG_LOGIC("RETURN SendPendingData");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1035
  return (nPacketsSent>0);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1036
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1037
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1038
uint32_t  TcpSocketImpl::UnAckDataCount ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1039
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1040
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1041
  return m_nextTxSequence - m_highestRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1042
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1043
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1044
uint32_t  TcpSocketImpl::BytesInFlight ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1045
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1046
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1047
  return m_highTxMark - m_highestRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1048
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1049
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1050
uint32_t  TcpSocketImpl::Window ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1051
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1052
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1053
  NS_LOG_LOGIC ("TcpSocketImpl::Window() "<<this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1054
  return std::min (m_rxWindowSize, m_cWnd.Get());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1055
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1056
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1057
uint32_t  TcpSocketImpl::AvailableWindow ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1058
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1059
  NS_LOG_FUNCTION_NOARGS ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1060
  uint32_t unack = UnAckDataCount (); // Number of outstanding bytes
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1061
  uint32_t win = Window ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1062
  if (win < unack) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1063
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1064
      return 0;  // No space available
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1065
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1066
  return (win - unack);       // Amount of window space available
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1067
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1068
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1069
uint32_t TcpSocketImpl::RxBufferFreeSpace()
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1070
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1071
  return m_rxBufMaxSize - m_rxBufSize;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1072
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1073
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1074
uint16_t TcpSocketImpl::AdvertisedWindowSize()
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1075
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1076
  uint32_t max = 0xffff;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1077
  return std::min(RxBufferFreeSpace(), max);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1078
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1079
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1080
void TcpSocketImpl::NewRx (Ptr<Packet> p,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1081
                        const TcpHeader& tcpHeader, 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1082
                        const Address& fromAddress)
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
  NS_LOG_FUNCTION (this << p << "tcpHeader " << fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1085
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewRx,"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1086
                << " seq " << tcpHeader.GetSequenceNumber()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1087
                << " ack " << tcpHeader.GetAckNumber()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1088
                << " p.size is " << p->GetSize () );
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1089
  NS_LOG_DEBUG ("TcpSocketImpl " << this <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1090
                " NewRx," <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1091
                " seq " << tcpHeader.GetSequenceNumber() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1092
                " ack " << tcpHeader.GetAckNumber() <<
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1093
                " p.size is " << p->GetSize());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1094
  States_t origState = m_state;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1095
  if (RxBufferFreeSpace() < p->GetSize()) 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1096
    { //if not enough room, fragment
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1097
      p = p->CreateFragment(0, RxBufferFreeSpace());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1098
    }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1099
  //XXX
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1100
  //fragmenting here MIGHT not be the right thing to do, since possibly we trim
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1101
  //the front and back off the packet below if it isn't all new data, so the 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1102
  //check against RxBufferFreeSpace and fragmentation should ideally occur
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1103
  //just before insertion into m_bufferedData, but this strategy is more
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1104
  //agressive in rejecting oversized packets and still gives acceptable TCP
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1105
  uint32_t s = p->GetSize ();  // Size of associated data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1106
  if (s == 0)
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1107
    {//if there is no data or no rx buffer space, just ack anyway
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1108
      SendEmptyPacket (TcpHeader::ACK);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1109
      return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1110
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1111
  // Log sequence received if enabled
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1112
  // NoteTimeSeq(LOG_SEQ_RX, h->sequenceNumber);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1113
  // Three possibilities
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1114
  // 1) Received seq is expected, buffer this, update rxAvailable, and ack
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1115
  // 2) Received seq is < expected, just re-ack previous
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1116
  // 3) Received seq is > expected, just re-ack previous and buffer data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1117
  if (tcpHeader.GetSequenceNumber () == m_nextRxSequence)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1118
    { // If seq is expected seq
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1119
      // Trim the end if necessary
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1120
      // 1) Update nextRxSeq
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1121
      // 2) Buffer this packet so Recv can read it
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1122
      // 3) Send the ack
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1123
      UnAckData_t::iterator next = m_bufferedData.upper_bound (m_nextRxSequence);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1124
      if (next != m_bufferedData.end ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1125
      {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1126
        SequenceNumber nextBufferedSeq = next->first;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1127
        if (m_nextRxSequence + SequenceNumber(s) > nextBufferedSeq)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1128
        {//tail end isn't all new, trim enough off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1129
          s = nextBufferedSeq - m_nextRxSequence;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1130
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1131
      }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1132
      p = p->CreateFragment (0,s);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1133
      m_nextRxSequence += s;           // Advance next expected sequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1134
      NS_LOG_LOGIC("Case 1, advanced nrxs to " << m_nextRxSequence );
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
  1135
      SocketAddressTag tag;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1136
      tag.SetAddress (fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1137
      p->AddTag (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
  1138
      //buffer this, it'll be read by call to Recv
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1139
      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
  1140
          m_bufferedData.find (tcpHeader.GetSequenceNumber () );
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1141
      NS_ASSERT(i == m_bufferedData.end ()); //no way it should have been found
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1142
      // Save for later delivery if there is room
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1143
      m_bufferedData[tcpHeader.GetSequenceNumber () ] = p;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1144
      m_rxAvailable += p->GetSize ();
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1145
      RxBufFinishInsert (tcpHeader.GetSequenceNumber ());
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1146
      m_rxBufSize += p->GetSize ();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1147
      NotifyDataRecv ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1148
      if (m_closeNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1149
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1150
          NS_LOG_LOGIC ("Tcp " << this << " HuH?  Got data after closeNotif");
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1151
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1152
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " adv rxseq by " << s);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1153
      if (m_pendingClose || (origState > ESTABLISHED))
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1154
        { // See if we can close now
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1155
          if (m_bufferedData.empty())
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1156
            {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1157
              ProcessPacketAction (PEER_CLOSE, p, tcpHeader, fromAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1158
            }
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
    }
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1161
  else if (tcpHeader.GetSequenceNumber () > m_nextRxSequence)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1162
    { // Need to buffer this one, but trim off the front and back if necessary
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1163
      NS_LOG_LOGIC ("Case 2, buffering " << tcpHeader.GetSequenceNumber () );
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1164
      UnAckData_t::iterator previous =
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1165
          m_bufferedData.lower_bound (tcpHeader.GetSequenceNumber ());
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1166
      SequenceNumber startSeq = tcpHeader.GetSequenceNumber();
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1167
      if (previous != m_bufferedData.begin ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1168
        {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1169
          --previous;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1170
          startSeq = previous->first + SequenceNumber(previous->second->GetSize());
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1171
          if (startSeq > tcpHeader.GetSequenceNumber ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1172
            {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1173
              s = tcpHeader.GetSequenceNumber () + SequenceNumber(s) - startSeq;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1174
            }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1175
          else
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1176
            {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1177
              startSeq = tcpHeader.GetSequenceNumber();
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1178
            }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1179
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1180
      //possibly trim off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1181
      UnAckData_t::iterator next = m_bufferedData.upper_bound (tcpHeader.GetSequenceNumber());
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1182
      if (next != m_bufferedData.end ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1183
      {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1184
        SequenceNumber nextBufferedSeq = next->first;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1185
        if (startSeq + SequenceNumber(s) > nextBufferedSeq)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1186
        {//tail end isn't all new either, trim enough off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1187
          s = nextBufferedSeq - startSeq;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1188
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1189
      }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1190
      p = p->CreateFragment (startSeq - tcpHeader.GetSequenceNumber (),s);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1191
      UnAckData_t::iterator i = 
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1192
          m_bufferedData.find (startSeq);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1193
      if (i != m_bufferedData.end () )
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1194
        {
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1195
          if(p->GetSize() > i->second->GetSize())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1196
          {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1197
            i->second = 0; // relase reference to already buffered
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1198
          }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1199
          else
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1200
          {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1201
            p = i->second;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1202
          }
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1203
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1204
      // Save for later delivery
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3251
diff changeset
  1205
      SocketAddressTag 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
  1206
      tag.SetAddress (fromAddress);
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
  1207
      p->AddTag (tag);
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1208
      m_bufferedData[startSeq] = p;  
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1209
      i = m_bufferedData.find (startSeq);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1210
      next = i;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1211
      ++next;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1212
      if(next != m_bufferedData.end())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1213
        {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1214
          NS_ASSERT(next->first >= i->first + SequenceNumber(i->second->GetSize ()));
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1215
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1216
    }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1217
  else if (tcpHeader.GetSequenceNumber () + SequenceNumber(s) > m_nextRxSequence)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1218
    {//parial new data case, only part of the packet is new data
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1219
      //trim the beginning
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1220
      s = tcpHeader.GetSequenceNumber () + SequenceNumber(s) - m_nextRxSequence; //how much new
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1221
      //possibly trim off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1222
      UnAckData_t::iterator next = m_bufferedData.upper_bound (m_nextRxSequence);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1223
      if (next != m_bufferedData.end ())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1224
      {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1225
        SequenceNumber nextBufferedSeq = next->first;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1226
        if (m_nextRxSequence + SequenceNumber(s) > nextBufferedSeq)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1227
        {//tail end isn't all new either, trim enough off the end
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1228
          s = nextBufferedSeq - m_nextRxSequence;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1229
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1230
      }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1231
      p = p->CreateFragment (m_nextRxSequence - tcpHeader.GetSequenceNumber (),s);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1232
      SequenceNumber start = m_nextRxSequence;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1233
      m_nextRxSequence += s;           // Advance next expected sequence
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1234
      SocketAddressTag tag;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1235
      tag.SetAddress (fromAddress);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1236
      p->AddTag (tag);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1237
      //buffer the new fragment, it'll be read by call to Recv
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1238
      UnAckData_t::iterator i = m_bufferedData.find (start);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1239
      if (i != m_bufferedData.end () ) //we found it already in the buffer
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1240
        {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1241
          i->second = 0; // relase reference to already buffered
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1242
        }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1243
      // Save for later delivery
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1244
      m_bufferedData[start] = p;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1245
      m_rxAvailable += p->GetSize ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1246
      m_rxBufSize += p->GetSize();
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1247
      RxBufFinishInsert(start);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1248
      NotifyDataRecv ();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1249
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1250
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1251
    { // debug
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1252
      NS_LOG_LOGIC("TCP " << this 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1253
               << " got seq " << tcpHeader.GetSequenceNumber ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1254
               << " expected " << m_nextRxSequence
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1255
               << "       flags " << tcpHeader.GetFlags ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1256
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1257
  // Now send a new ack packet acknowledging all received and delivered data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1258
  if(++m_delAckCount >= m_delAckMaxCount)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1259
  {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1260
    m_delAckEvent.Cancel();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1261
    m_delAckCount = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1262
    SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1263
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1264
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1265
  {
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1266
    m_delAckEvent = Simulator::Schedule (m_delAckTimeout, &TcpSocketImpl::DelAckTimeout, this);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1267
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1268
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1269
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1270
void TcpSocketImpl::RxBufFinishInsert (SequenceNumber seq)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1271
{
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1272
  //putting data into the buffer might have filled in a sequence gap so we have
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1273
  //to iterate through the list to find the largest contiguous sequenced chunk,
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1274
  //and update m_rxAvailable and m_nextRxSequence appropriately
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1275
  UnAckData_t::iterator i = m_bufferedData.find (seq);
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1276
  UnAckData_t::iterator next = i;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1277
  ++next;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1278
  //make sure the buffer is logically sequenced
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1279
  if(next != m_bufferedData.end())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1280
  {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1281
    NS_ASSERT(next->first >= i->first + SequenceNumber(i->second->GetSize ()));
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1282
  }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1283
  while(next != m_bufferedData.end())
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1284
  {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1285
    if(i->first + SequenceNumber(i->second->GetSize ()) == next->first)
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1286
    {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1287
      //next packet is in sequence, count it
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1288
      m_rxAvailable += next->second->GetSize();
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1289
      m_nextRxSequence += next->second->GetSize();
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1290
    }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1291
    else
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1292
    {
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1293
      break; //no more in this contiguous chunk
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1294
    }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1295
    ++i;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1296
    ++next;
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1297
  }
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1298
}
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3475
diff changeset
  1299
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1300
void TcpSocketImpl::DelAckTimeout ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1301
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1302
  m_delAckCount = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1303
  SendEmptyPacket (TcpHeader::ACK);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1304
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1305
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1306
void TcpSocketImpl::CommonNewAck (SequenceNumber ack, bool skipTimer)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1307
{ // CommonNewAck is called only for "New" (non-duplicate) acks
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1308
  // and MUST be called by any subclass, from the NewAck function
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1309
  // Always cancel any pending re-tx timer on new acknowledgement
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1310
  NS_LOG_FUNCTION (this << ack << skipTimer); 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1311
  //DEBUG(1,(cout << "TCP " << this << "Cancelling retx timer " << endl));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1312
  if (!skipTimer)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1313
    {
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1314
      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
  1315
                    << (Simulator::Now () + 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1316
                        Simulator::GetDelayLeft (m_retxEvent)).GetSeconds());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1317
      m_retxEvent.Cancel ();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1318
      //On recieving a "New" ack we restart retransmission timer .. RFC 2988
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1319
      Time rto = m_rtt->RetransmitTimeout ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1320
      NS_LOG_LOGIC (this<<" Schedule ReTxTimeout at time " 
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1321
          << Simulator::Now ().GetSeconds () << " to expire at time " 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1322
          << (Simulator::Now () + rto).GetSeconds ());
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1323
      m_retxEvent = 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1324
          Simulator::Schedule (rto, &TcpSocketImpl::ReTxTimeout, this);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1325
    }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1326
  if (m_rxWindowSize == 0 && m_persistEvent.IsExpired ()) //zerowindow
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1327
    {
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1328
      NS_LOG_LOGIC (this<<"Enter zerowindow persist state");
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1329
      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
  1330
                    << (Simulator::Now () + 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1331
                        Simulator::GetDelayLeft (m_retxEvent)).GetSeconds());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1332
      m_retxEvent.Cancel ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1333
      NS_LOG_LOGIC ("Schedule persist timeout at time " 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1334
                    <<Simulator::Now ().GetSeconds () << " to expire at time "
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1335
                    << (Simulator::Now () + m_persistTime).GetSeconds());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1336
      m_persistEvent = 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1337
      Simulator::Schedule (m_persistTime, &TcpSocketImpl::PersistTimeout, this);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1338
      NS_ASSERT (m_persistTime == Simulator::GetDelayLeft (m_persistEvent));
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1339
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1340
  NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1341
           << " numberAck " << (ack - m_highestRxAck)); // Number bytes ack'ed
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1342
  m_highestRxAck = ack;         // Note the highest recieved Ack
3327
ea16c44eb90d Apply Patch for Bug 237
Craig Dowell <craigdo@ee.washington.edu>
parents: 3291
diff changeset
  1343
  if (GetTxAvailable () > 0)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1344
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1345
      NotifySend (GetTxAvailable ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1346
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1347
  if (ack > m_nextTxSequence) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1348
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1349
      m_nextTxSequence = ack; // If advanced
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1350
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1351
  // See if all pending ack'ed; if so we can delete the data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1352
  if (m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1353
    { // Data exists, see if can be deleted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1354
      if (m_pendingData->SizeFromSeq (m_firstPendingSequence, m_highestRxAck) == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1355
        { // All pending acked, can be deleted
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1356
          m_pendingData->Clear ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1357
          delete m_pendingData;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1358
          m_pendingData = 0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1359
          // Insure no re-tx timer
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1360
          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
  1361
                    << (Simulator::Now () + 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1362
                        Simulator::GetDelayLeft (m_retxEvent)).GetSeconds());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1363
          m_retxEvent.Cancel ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1364
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1365
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1366
  // Try to send more data
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1367
  SendPendingData();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1368
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1369
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1370
Ptr<TcpSocketImpl> TcpSocketImpl::Copy ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1371
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1372
  return CopyObject<TcpSocketImpl> (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1373
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1374
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1375
void TcpSocketImpl::NewAck (SequenceNumber seq)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1376
{ // New acknowledgement up to sequence number "seq"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1377
  // Adjust congestion window in response to new ack's received
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1378
  NS_LOG_FUNCTION (this << seq);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1379
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewAck "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1380
           << " seq " << seq
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1381
           << " cWnd " << m_cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1382
           << " ssThresh " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1383
  if (m_cWnd < m_ssThresh)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1384
    { // Slow start mode, add one segSize to cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1385
      m_cWnd += m_segmentSize;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1386
      NS_LOG_LOGIC ("TcpSocketImpl " << this << " NewCWnd SlowStart, cWnd " << m_cWnd 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1387
          << " sst " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1388
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1389
  else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1390
    { // Congestion avoidance mode, adjust by (ackBytes*segSize) / cWnd
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1391
      double adder =  ((double) m_segmentSize * m_segmentSize) / m_cWnd.Get();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1392
      if (adder < 1.0) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1393
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1394
          adder = 1.0;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1395
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1396
      m_cWnd += (uint32_t) adder;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1397
      NS_LOG_LOGIC ("NewCWnd CongAvoid, cWnd " << m_cWnd 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1398
           << " sst " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1399
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1400
  CommonNewAck (seq, false);           // Complete newAck processing
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1401
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1402
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1403
void TcpSocketImpl::DupAck (const TcpHeader& t, uint32_t count)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1404
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1405
  NS_LOG_FUNCTION (this << "t " << count);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1406
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " DupAck " <<  t.GetAckNumber ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1407
      << ", count " << count
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1408
      << ", time " << Simulator::Now ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1409
  if (count == 3)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1410
  { // Count of three indicates triple duplicate ack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1411
    m_ssThresh = Window () / 2; // Per RFC2581
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1412
    m_ssThresh = std::max (m_ssThresh, 2 * m_segmentSize);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1413
    NS_LOG_LOGIC("TcpSocketImpl " << this << "Tahoe TDA, time " << Simulator::Now ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1414
        << " seq " << t.GetAckNumber ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1415
        << " in flight " << BytesInFlight ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1416
        << " new ssthresh " << m_ssThresh);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1417
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1418
    m_cWnd = m_segmentSize; // Collapse cwnd (re-enter slowstart)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1419
    // For Tahoe, we also reset nextTxSeq
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1420
    m_nextTxSequence = m_highestRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1421
    SendPendingData ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1422
  }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1423
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1424
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1425
void TcpSocketImpl::ReTxTimeout ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1426
{ // Retransmit timeout
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1427
  NS_LOG_FUNCTION (this);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1428
  NS_LOG_LOGIC (this<<" ReTxTimeout Expired at time "<<Simulator::Now ().GetSeconds());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1429
  m_ssThresh = Window () / 2; // Per RFC2581
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1430
  m_ssThresh = std::max (m_ssThresh, 2 * m_segmentSize);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1431
  // Set cWnd to segSize on timeout,  per rfc2581
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1432
  // Collapse congestion window (re-enter slowstart)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1433
  m_cWnd = m_segmentSize;           
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1434
  m_nextTxSequence = m_highestRxAck; // Start from highest Ack
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1435
  m_rtt->IncreaseMultiplier (); // DoubleValue timeout value for next retx timer
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1436
  Retransmit ();             // Retransmit the packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1437
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1438
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1439
void TcpSocketImpl::LastAckTimeout ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1440
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1441
  m_lastAckEvent.Cancel ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1442
  if (m_state == LAST_ACK)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1443
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1444
      Actions_t action = ProcessEvent (TIMEOUT);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1445
      ProcessAction (action);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1446
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1447
  if (!m_closeNotified)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1448
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1449
      m_closeNotified = true;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1450
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1451
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1452
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1453
void TcpSocketImpl::PersistTimeout ()
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1454
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1455
  NS_LOG_LOGIC ("PersistTimeout expired at "<<Simulator::Now ().GetSeconds ());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1456
  m_persistTime = Scalar(2)*m_persistTime;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1457
  m_persistTime = std::min(Seconds(60),m_persistTime); //maxes out at 60
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1458
  //the persist timeout sends exactly one byte probes
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1459
  //this is explicit in stevens, and kind of in rfc793 p42, rfc1122 sec4.2.2.17
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1460
  Ptr<Packet> p =
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1461
    m_pendingData->CopyFromSeq(1,m_firstPendingSequence,m_nextTxSequence);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1462
  TcpHeader tcpHeader;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1463
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1464
  tcpHeader.SetAckNumber (m_nextRxSequence);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1465
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1466
  tcpHeader.SetDestinationPort (m_remotePort);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1467
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1468
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1469
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1470
    m_remoteAddress);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1471
  NS_LOG_LOGIC ("Schedule persist timeout at time " 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1472
                    <<Simulator::Now ().GetSeconds () << " to expire at time "
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1473
                    << (Simulator::Now () + m_persistTime).GetSeconds());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1474
  m_persistEvent = 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1475
    Simulator::Schedule (m_persistTime, &TcpSocketImpl::PersistTimeout, this);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1476
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1477
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1478
void TcpSocketImpl::Retransmit ()
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1479
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1480
  NS_LOG_FUNCTION (this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1481
  uint8_t flags = TcpHeader::NONE;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1482
  if (m_state == SYN_SENT) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1483
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1484
      if (m_cnCount > 0) 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1485
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1486
          SendEmptyPacket (TcpHeader::SYN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1487
          return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1488
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1489
      else
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1490
        {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1491
          NotifyConnectionFailed ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1492
          return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1493
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1494
    } 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1495
  if (!m_pendingData)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1496
    {
3276
8869a79a391f Changes for bug 205, unlisted FIN bug
Craig Dowell <craigdo@ee.washington.edu>
parents: 3272
diff changeset
  1497
      if (m_state == FIN_WAIT_1)
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1498
        { // Must have lost FIN, re-send
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1499
          SendEmptyPacket (TcpHeader::FIN);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1500
        }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1501
      return;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1502
    }
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1503
  NS_ASSERT(m_nextTxSequence == m_highestRxAck);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1504
  Ptr<Packet> p = m_pendingData->CopyFromSeq (m_segmentSize,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1505
                                            m_firstPendingSequence,
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1506
                                            m_nextTxSequence);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1507
  // Calculate remaining data for COE check
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1508
  uint32_t remainingData = m_pendingData->SizeFromSeq (
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1509
      m_firstPendingSequence,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1510
      m_nextTxSequence + SequenceNumber(p->GetSize ()));
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1511
  if (m_closeOnEmpty && remainingData == 0)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1512
    { // Add the FIN flag
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1513
      flags = flags | TcpHeader::FIN;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1514
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1515
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1516
  NS_LOG_LOGIC ("TcpSocketImpl " << this << " retxing seq " << m_highestRxAck);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1517
  if (m_retxEvent.IsExpired () )
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1518
    {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1519
      Time rto = m_rtt->RetransmitTimeout ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1520
      NS_LOG_LOGIC (this<<" Schedule ReTxTimeout at time "
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1521
          << Simulator::Now ().GetSeconds () << " to expire at time "
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1522
          << (Simulator::Now () + rto).GetSeconds ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1523
      m_retxEvent = Simulator::Schedule (rto,&TcpSocketImpl::ReTxTimeout,this);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1524
    }
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1525
  m_rtt->SentSeq (m_highestRxAck,p->GetSize ());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1526
  // And send the packet
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1527
  TcpHeader tcpHeader;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1528
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1529
  tcpHeader.SetAckNumber (m_nextRxSequence);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1530
  tcpHeader.SetSourcePort (m_endPoint->GetLocalPort());
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1531
  tcpHeader.SetDestinationPort (m_remotePort);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1532
  tcpHeader.SetFlags (flags);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1533
  tcpHeader.SetWindowSize (AdvertisedWindowSize());
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1534
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1535
  m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1536
    m_remoteAddress);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1537
}
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1538
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1539
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1540
TcpSocketImpl::SetSndBufSize (uint32_t size)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1541
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1542
  m_sndBufSize = size;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1543
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1544
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1545
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1546
TcpSocketImpl::GetSndBufSize (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1547
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1548
  return m_sndBufSize;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1549
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1550
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1551
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1552
TcpSocketImpl::SetRcvBufSize (uint32_t size)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1553
{
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1554
  m_rxBufMaxSize = size;
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1555
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1556
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1557
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1558
TcpSocketImpl::GetRcvBufSize (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1559
{
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1560
  return m_rxBufMaxSize;
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1561
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1562
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1563
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1564
TcpSocketImpl::SetSegSize (uint32_t size)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1565
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1566
  m_segmentSize = size;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1567
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1568
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1569
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1570
TcpSocketImpl::GetSegSize (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1571
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1572
  return m_segmentSize;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1573
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1574
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1575
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1576
TcpSocketImpl::SetSSThresh (uint32_t threshold)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1577
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1578
  m_ssThresh = threshold;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1579
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1580
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1581
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1582
TcpSocketImpl::GetSSThresh (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1583
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1584
  return m_ssThresh;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1585
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1586
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1587
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1588
TcpSocketImpl::SetInitialCwnd (uint32_t cwnd)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1589
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1590
  m_initialCWnd = cwnd;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1591
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1592
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1593
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1594
TcpSocketImpl::GetInitialCwnd (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1595
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1596
  return m_initialCWnd;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1597
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1598
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1599
void 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1600
TcpSocketImpl::SetConnTimeout (Time timeout)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1601
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1602
  m_cnTimeout = timeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1603
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1604
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1605
Time
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1606
TcpSocketImpl::GetConnTimeout (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1607
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1608
  return m_cnTimeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1609
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1610
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1611
void 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1612
TcpSocketImpl::SetConnCount (uint32_t count)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1613
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1614
  m_cnCount = count;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1615
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1616
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1617
uint32_t 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1618
TcpSocketImpl::GetConnCount (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1619
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1620
  return m_cnCount;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1621
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1622
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1623
void 
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1624
TcpSocketImpl::SetDelAckTimeout (Time timeout)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1625
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1626
  m_delAckTimeout = timeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1627
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1628
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1629
Time
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1630
TcpSocketImpl::GetDelAckTimeout (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1631
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1632
  return m_delAckTimeout;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1633
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1634
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1635
void
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1636
TcpSocketImpl::SetDelAckMaxCount (uint32_t count)
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1637
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1638
  m_delAckMaxCount = count;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1639
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1640
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1641
uint32_t
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1642
TcpSocketImpl::GetDelAckMaxCount (void) const
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1643
{
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1644
  return m_delAckMaxCount;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1645
}
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
  1646
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1647
}//namespace ns3
3528
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1648
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1649
#ifdef RUN_SELF_TESTS
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1650
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1651
#include "ns3/test.h"
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1652
#include "ns3/socket-factory.h"
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1653
#include "ns3/tcp-socket-factory.h"
3528
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1654
#include "ns3/simulator.h"
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1655
#include "ns3/simple-channel.h"
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1656
#include "ns3/simple-net-device.h"
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1657
#include "ns3/drop-tail-queue.h"
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1658
#include "ns3/config.h"
3528
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1659
#include "internet-stack.h"
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1660
#include <string>
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1661
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1662
namespace ns3 {
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1663
	
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1664
class TcpSocketImplTest: public Test
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1665
{
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1666
  public:
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1667
  TcpSocketImplTest ();
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1668
  virtual bool RunTests (void);
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1669
  private:
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1670
  //test 1, which sends string "Hello world" server->client
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1671
  void Test1 (void);
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1672
  void Test1_HandleConnectionCreated (Ptr<Socket>, const Address &);
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1673
  void Test1_HandleRecv (Ptr<Socket> sock);
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1674
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1675
  //test 2, which sends a number of bytes server->client
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1676
  void Test2 (uint32_t payloadSize);
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1677
  void Test2_HandleConnectionCreated (Ptr<Socket>, const Address &);
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1678
  void Test2_HandleRecv (Ptr<Socket> sock);
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1679
  uint32_t test2_payloadSize;
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1680
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1681
  //test 3, which makes sure the rx buffer is finite
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1682
  void Test3 (uint32_t payloadSize);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1683
  void Test3_HandleConnectionCreated (Ptr<Socket>, const Address &);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1684
  void Test3_HandleRecv (Ptr<Socket> sock);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1685
  uint32_t test3_payloadSize;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1686
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1687
  //helpers to make topology construction easier
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1688
  Ptr<Node> CreateInternetNode ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1689
  Ptr<SimpleNetDevice> AddSimpleNetDevice (Ptr<Node>,const char*,const char*);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1690
  void SetupDefaultSim ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1691
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1692
  //reset all of the below state for another run
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1693
  void Reset ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1694
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1695
  //all of the state this class needs; basically both ends of the connection,
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1696
  //and this test kind of acts as an single application running on both nodes
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1697
  //simultaneously
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1698
  Ptr<Node> node0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1699
  Ptr<Node> node1;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1700
  Ptr<SimpleNetDevice> dev0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1701
  Ptr<SimpleNetDevice> dev1;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1702
  Ptr<SimpleChannel> channel;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1703
  Ptr<Socket> listeningSock;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1704
  Ptr<Socket> sock0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1705
  Ptr<Socket> sock1;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1706
  uint32_t rxBytes0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1707
  uint32_t rxBytes1;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1708
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1709
  uint8_t* rxPayload;
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1710
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1711
  bool result;
3528
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1712
};
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1713
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1714
TcpSocketImplTest::TcpSocketImplTest ()
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1715
  : Test ("TcpSocketImpl"), 
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1716
    rxBytes0 (0),
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1717
    rxBytes1 (0),
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1718
    rxPayload (0),
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1719
    result (true)
3528
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1720
{
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1721
}
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1722
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1723
bool
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1724
TcpSocketImplTest::RunTests (void)
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1725
{
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1726
  Test1();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1727
  if (!result) return false;
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1728
  Test2(600);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1729
  if (!result) return false;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1730
  Test3(20000);
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1731
  return result;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1732
}
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1733
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1734
//-----------------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1735
//test 1-----------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1736
//-----------------------------------------------------------------------------
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1737
void
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1738
TcpSocketImplTest::Test1 ()
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1739
{
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1740
  SetupDefaultSim ();
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1741
  listeningSock->SetAcceptCallback 
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1742
      (MakeNullCallback<bool, Ptr< Socket >, const Address &> (),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1743
       MakeCallback(&TcpSocketImplTest::Test1_HandleConnectionCreated,this));
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1744
  sock1->SetRecvCallback (MakeCallback(&TcpSocketImplTest::Test1_HandleRecv, this));
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1745
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1746
  Simulator::Run ();
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1747
  Simulator::Destroy ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1748
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1749
  result = result && (rxBytes1 == 13);
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1750
  result = result && (strcmp((const char*) rxPayload,"Hello World!") == 0);
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1751
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1752
  Reset ();
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1753
}
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1754
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1755
void
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1756
TcpSocketImplTest::Test1_HandleConnectionCreated (Ptr<Socket> s, const Address & addr)
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1757
{
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1758
  NS_ASSERT(s != listeningSock);
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1759
  NS_ASSERT(sock0 == 0);
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1760
  sock0 = s;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1761
  const uint8_t* hello = (uint8_t*)"Hello World!";
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1762
  Ptr<Packet> p = Create<Packet> (hello, 13);
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1763
  sock0->Send(p);
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1764
  
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1765
  sock0->SetRecvCallback (MakeCallback(&TcpSocketImplTest::Test1_HandleRecv, this));
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1766
}
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1767
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1768
void
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1769
TcpSocketImplTest::Test1_HandleRecv (Ptr<Socket> sock)
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1770
{
3545
9358e0be63d2 Fix a unit test typo (thanks Providence Salumu Munga
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3533
diff changeset
  1771
  NS_ASSERT (sock == sock0 || sock == sock1);
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1772
  Ptr<Packet> p = sock->Recv();
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1773
  uint32_t sz = p->GetSize();
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1774
  if (sock == sock1)
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1775
  {
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1776
    rxBytes1 += sz;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1777
    rxPayload = new uint8_t[sz];
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1778
    memcpy (rxPayload, p->PeekData(), sz);
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1779
  }
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1780
  else
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1781
  {
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1782
    NS_FATAL_ERROR ("Recv from unknown socket "<<sock);
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1783
  }
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1784
}
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1785
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1786
//-----------------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1787
//test 2-----------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1788
//-----------------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1789
void
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1790
TcpSocketImplTest::Test2 (uint32_t payloadSize)
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1791
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1792
  test2_payloadSize = payloadSize;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1793
  SetupDefaultSim ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1794
  listeningSock->SetAcceptCallback 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1795
      (MakeNullCallback<bool, Ptr< Socket >, const Address &> (),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1796
       MakeCallback(&TcpSocketImplTest::Test2_HandleConnectionCreated,this));
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1797
  sock1->SetRecvCallback (MakeCallback(&TcpSocketImplTest::Test2_HandleRecv, this));
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1798
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1799
  Simulator::Run ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1800
  Simulator::Destroy ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1801
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1802
  result = result && (rxBytes1 == test2_payloadSize);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1803
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1804
  Reset ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1805
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1806
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1807
void
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1808
TcpSocketImplTest::Test2_HandleConnectionCreated (Ptr<Socket> s, const Address & addr)
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1809
{
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1810
  NS_ASSERT(s != listeningSock);
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1811
  NS_ASSERT(sock0 == 0);
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1812
  sock0 = s;
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1813
  Ptr<Packet> p = Create<Packet> (test2_payloadSize);
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1814
  sock0->Send(p);
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1815
  
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1816
  sock0->SetRecvCallback (MakeCallback(&TcpSocketImplTest::Test2_HandleRecv, this));
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1817
}
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1818
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1819
void
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1820
TcpSocketImplTest::Test2_HandleRecv (Ptr<Socket> sock)
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1821
{
3545
9358e0be63d2 Fix a unit test typo (thanks Providence Salumu Munga
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3533
diff changeset
  1822
  NS_ASSERT (sock == sock0 || sock == sock1);
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1823
  Ptr<Packet> p = sock->Recv();
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1824
  uint32_t sz = p->GetSize();
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1825
  if (sock == sock1)
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1826
  {
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1827
    rxBytes1 += sz;
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1828
  }
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1829
  else
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1830
  {
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1831
    NS_FATAL_ERROR ("Not supposed to be back traffic in test 2..."<<sock);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1832
  }
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1833
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1834
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1835
//-----------------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1836
//test 3-----------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1837
//-----------------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1838
void
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1839
TcpSocketImplTest::Test3 (uint32_t payloadSize)
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1840
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1841
  Config::SetDefault ("ns3::TcpSocket::RcvBufSize", UintegerValue (10000));
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1842
  test3_payloadSize = payloadSize;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1843
  SetupDefaultSim ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1844
  listeningSock->SetAcceptCallback 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1845
      (MakeNullCallback<bool, Ptr< Socket >, const Address &> (),
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1846
       MakeCallback(&TcpSocketImplTest::Test3_HandleConnectionCreated,this));
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1847
  sock1->SetRecvCallback (MakeCallback(&TcpSocketImplTest::Test3_HandleRecv, this));
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1848
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1849
  Simulator::Run ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1850
  Simulator::Destroy ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1851
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1852
  result = result && (rxBytes1 == test3_payloadSize);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1853
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1854
  Reset();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1855
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1856
void
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1857
TcpSocketImplTest::Test3_HandleConnectionCreated (Ptr<Socket> s, const Address &)
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1858
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1859
  NS_ASSERT(s != listeningSock);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1860
  NS_ASSERT(sock0 == 0);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1861
  sock0 = s;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1862
  Ptr<Packet> p = Create<Packet> (test3_payloadSize);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1863
  sock0->Send(p);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1864
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1865
void
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1866
TcpSocketImplTest::Test3_HandleRecv (Ptr<Socket> sock)
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1867
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1868
  NS_ASSERT_MSG (sock == sock1, "Not supposed to be back traffic in test 3... ");
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1869
  if(sock->GetRxAvailable() >= 10000 ) //perform batch reads every 10000 bytes
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1870
  {
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1871
    Ptr<Packet> p = sock->Recv();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1872
    uint32_t sz = p->GetSize();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1873
    rxBytes1 += sz;
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1874
  }
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1875
}
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1876
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1877
//-----------------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1878
//helpers----------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1879
//-----------------------------------------------------------------------------
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1880
Ptr<Node>
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1881
TcpSocketImplTest::CreateInternetNode ()
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1882
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1883
  Ptr<Node> node = CreateObject<Node> ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1884
  AddInternetStack (node);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1885
  return node;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1886
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1887
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1888
Ptr<SimpleNetDevice>
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1889
TcpSocketImplTest::AddSimpleNetDevice (Ptr<Node> node, const char* ipaddr, const char* netmask)
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1890
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1891
  Ptr<SimpleNetDevice> dev = CreateObject<SimpleNetDevice> ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1892
  dev->SetAddress (Mac48Address::Allocate ());
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1893
  node->AddDevice (dev);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1894
  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1895
  uint32_t ndid = ipv4->AddInterface (dev);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1896
  ipv4->SetAddress (ndid, Ipv4Address (ipaddr));
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1897
  ipv4->SetNetworkMask (ndid, Ipv4Mask (netmask));
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1898
  ipv4->SetUp (ndid);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1899
  return dev;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1900
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1901
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1902
void 
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1903
TcpSocketImplTest::SetupDefaultSim ()
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1904
{
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1905
  const char* netmask = "255.255.255.0";
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1906
  const char* ipaddr0 = "192.168.1.1";
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1907
  const char* ipaddr1 = "192.168.1.2";
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1908
  node0 = CreateInternetNode ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1909
  node1 = CreateInternetNode ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1910
  dev0 = AddSimpleNetDevice (node0, ipaddr0, netmask);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1911
  dev1 = AddSimpleNetDevice (node1, ipaddr1, netmask);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1912
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1913
  channel = CreateObject<SimpleChannel> ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1914
  dev0->SetChannel (channel);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1915
  dev1->SetChannel (channel);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1916
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1917
  Ptr<SocketFactory> sockFactory0 = node0->GetObject<TcpSocketFactory> ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1918
  Ptr<SocketFactory> sockFactory1 = node1->GetObject<TcpSocketFactory> ();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1919
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1920
  listeningSock = sockFactory0->CreateSocket();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1921
  sock1 = sockFactory1->CreateSocket();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1922
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1923
  uint16_t port = 50000;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1924
  InetSocketAddress serverlocaladdr (Ipv4Address::GetAny(), port);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1925
  InetSocketAddress serverremoteaddr (Ipv4Address(ipaddr0), port);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1926
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1927
  listeningSock->Bind(serverlocaladdr);
3772
f0d8608ab155 Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents: 3644
diff changeset
  1928
  listeningSock->Listen ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1929
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1930
  sock1->Connect(serverremoteaddr);
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1931
}
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3643
diff changeset
  1932
3533
46446b2e3c9d Add another test to TcpSocketImplTest
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3532
diff changeset
  1933
void
3532
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1934
TcpSocketImplTest::Reset ()
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1935
{
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1936
  node0 = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1937
  node1 = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1938
  dev0 = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1939
  dev1 = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1940
  channel = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1941
  listeningSock = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1942
  sock0 = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1943
  sock1 = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1944
  rxBytes0 = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1945
  rxBytes1 = 0;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1946
  delete[] rxPayload;
a88c0d54e43b Add a test to TcpSocketImpl unit tests
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3529
diff changeset
  1947
  rxPayload = 0;
3528
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1948
}
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1949
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1950
static TcpSocketImplTest gTcpSocketImplTest;
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1951
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1952
}//namespace ns3
10c667a90efa Stub TcpSocketImpl unit test
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
  1953
3529
fdf978993930 make it build with gcc 4.1.3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3528
diff changeset
  1954
#endif /* RUN_SELF_TESTS */