src/internet-stack/tcp-socket-impl.h
author Antti Mäkelä <zarhan@cc.hut.fi>
Wed, 02 Jun 2010 10:44:48 -0400
changeset 6328 f03f4d82daaf
parent 6273 8d70de29d514
child 6434 ac8b4bf77e50
permissions -rw-r--r--
Bug 902 - TCP: handle out-of-order packets during connection shutdown
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2007 Georgia Tech Research Corporation
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 *
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * Author: Raj Bhattacharjea <raj.b@gatech.edu>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
#ifndef TCP_SOCKET_IMPL_H
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
#define TCP_SOCKET_IMPL_H
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
#include <stdint.h>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include <queue>
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
#include "ns3/callback.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include "ns3/traced-value.h"
3134
1890d6ee27a1 Add abstract base class TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3131
diff changeset
    27
#include "ns3/tcp-socket.h"
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ns3/ptr.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
#include "ns3/ipv4-address.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
#include "ns3/event-id.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
#include "tcp-typedefs.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
#include "pending-data.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
#include "sequence-number.h"
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
#include "rtt-estimator.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
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
namespace ns3 {
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
class Ipv4EndPoint;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
class Node;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
class Packet;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
class TcpL4Protocol;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
class TcpHeader;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
3266
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    45
/**
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    46
 * \ingroup socket
3691
372f4475dc47 Doxygen for internet-stack
Tom Henderson <tomh@tomh.org>
parents: 3644
diff changeset
    47
 * \ingroup tcp
3266
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    48
 *
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    49
 * \brief An implementation of a stream socket using TCP.
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    50
 *
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    51
 * This class contains an implementation of TCP Tahoe, as well as a sockets
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    52
 * interface for talking to TCP.  Features include connection orientation,
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    53
 * reliability through cumulative acknowledgements, congestion and flow 
3399
5782cdf815e1 Add some additional TCP dox about RFC compliance
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
    54
 * control.  Finite send buffer semantics are modeled, but as of yet, finite
5782cdf815e1 Add some additional TCP dox about RFC compliance
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
    55
 * receive buffer modelling is unimplemented.
5782cdf815e1 Add some additional TCP dox about RFC compliance
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
    56
 *
6273
8d70de29d514 spell check, mostly in comments.
Andrey Mazo <mazo@iitp.ru>
parents: 5971
diff changeset
    57
 * The closedown of these sockets is as of yet not compliant with the relevant
3399
5782cdf815e1 Add some additional TCP dox about RFC compliance
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
    58
 * RFCs, i.e. the FIN handshaking isn't correct.  While this is visible at the
5782cdf815e1 Add some additional TCP dox about RFC compliance
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
    59
 * PCAP tracing level, it has no effect on the statistics users are interested
5782cdf815e1 Add some additional TCP dox about RFC compliance
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3327
diff changeset
    60
 * in, i.e. throughput, delay, etc. of actual payload data.
3266
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    61
 *
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    62
 * Asynchronous callbacks to provide notifications to higher layers that a 
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    63
 * protocol event has occured, such as space freeing up in the send buffer
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    64
 * or new data arriving in the receive buffer.
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    65
 */
3134
1890d6ee27a1 Add abstract base class TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3131
diff changeset
    66
class TcpSocketImpl : public TcpSocket
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
{
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
public:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
  static TypeId GetTypeId (void);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    70
  /**
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
   * Create an unbound tcp socket.
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
   */
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
  TcpSocketImpl ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    74
  TcpSocketImpl (const TcpSocketImpl& sock);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    75
  virtual ~TcpSocketImpl ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    77
  void SetNode (Ptr<Node> node);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
  void SetTcp (Ptr<TcpL4Protocol> tcp);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
  void SetRtt (Ptr<RttEstimator> rtt);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    80
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
  virtual enum SocketErrno GetErrno (void) const;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
  virtual Ptr<Node> GetNode (void) const;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
  virtual int Bind (void);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
  virtual int Bind (const Address &address);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
  virtual int Close (void);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
  virtual int ShutdownSend (void);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
  virtual int ShutdownRecv (void);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
  virtual int Connect(const Address &address);
3772
f0d8608ab155 Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents: 3691
diff changeset
    89
  virtual int Listen(void);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
  virtual uint32_t GetTxAvailable (void) const;
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3252
diff changeset
    91
  virtual int Send (Ptr<Packet> p, uint32_t flags);
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3252
diff changeset
    92
  virtual int SendTo(Ptr<Packet> p, uint32_t flags, const Address &toAddress);
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3252
diff changeset
    93
  virtual uint32_t GetRxAvailable (void) const;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
3269
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3252
diff changeset
    95
  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
448134601b03 RecvFrom() expansion, add flags parameter to some Send calls
Tom Henderson <tomh@tomh.org>
parents: 3252
diff changeset
    96
    Address &fromAddress);
3778
78c4c41557f3 Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents: 3772
diff changeset
    97
  virtual int GetSockName (Address &address) const; 
5856
7fd20c798a7d bug 742: Implementation of SO_BINDTODEVICE
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 5377
diff changeset
    98
  virtual void BindToNetDevice (Ptr<NetDevice> netdevice);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    99
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
private:
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
  friend class Tcp;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
  // invoked by Tcp class
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
  int FinishBind (void);
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5856
diff changeset
   104
  void ForwardUp (Ptr<Packet> p, Ipv4Address saddr, Ipv4Address daddr, uint16_t port);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
  void Destroy (void);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   106
  int DoSendTo (Ptr<Packet> p, const Address &daddr);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   107
  int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   108
  void SendEmptyPacket(uint8_t flags);
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 3778
diff changeset
   109
  void SendRST();
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 3778
diff changeset
   110
  
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
  //methods for state
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
  bool ProcessAction (Actions_t a);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113
  bool ProcessAction (Actions_t a, const TcpHeader& tcpHeader,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   114
                      Ipv4Address saddr, Ipv4Address daddr);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   115
  bool ProcessPacketAction (Actions_t a, Ptr<Packet> p,
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   116
                                       const TcpHeader& tcpHeader,
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5856
diff changeset
   117
                                       const Address& fromAddress,
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5856
diff changeset
   118
                                       const Address& toAddress);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   119
  Actions_t ProcessEvent (Events_t e);
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
  bool SendPendingData(bool withAck = false);
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5856
diff changeset
   121
  void CompleteFork(Ptr<Packet>, const TcpHeader&, const Address& fromAddress, const Address& toAddress);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   122
  void ConnectionSucceeded();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   123
  
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   124
  //methods for window management
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   125
  virtual uint32_t  UnAckDataCount(); // Return count of number of unacked bytes
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
  virtual uint32_t  BytesInFlight();  // Return total bytes in flight
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   127
  virtual uint32_t  Window();         // Return window size (integer)
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   128
  virtual uint32_t  AvailableWindow();// Return unfilled portion of window
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   129
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   130
  //methods for Rx buffer management
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   131
  uint32_t RxBufferFreeSpace();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   132
  uint16_t AdvertisedWindowSize();
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   133
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
  // Manage data tx/rx
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5856
diff changeset
   135
  void NewRx (Ptr<Packet>, const TcpHeader&, const Address& fromAddress, const Address& toAddress);
3493
53ec8893863d Fix TcpSocketImpl rx buffer logic (closes 248)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3399
diff changeset
   136
  void RxBufFinishInsert (SequenceNumber);
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
  Ptr<TcpSocketImpl> Copy ();
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 3778
diff changeset
   138
  virtual void NewAck (SequenceNumber seq); 
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 3778
diff changeset
   139
  virtual void DupAck (const TcpHeader& t, uint32_t count); 
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 3778
diff changeset
   140
  virtual void ReTxTimeout ();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
  void DelAckTimeout ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
  void LastAckTimeout ();
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   143
  void PersistTimeout ();
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
  void Retransmit ();
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
  void CommonNewAck (SequenceNumber seq, bool skipTimer = false);
5377
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 3778
diff changeset
   146
  // All timers are cancelled when the endpoint is deleted, to insure
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 3778
diff changeset
   147
  // we don't have additional activity
c54b36fb7317 TCP bug fixes 424, 426, 559, 663, 664, 697
Josh Pelkey <jpelkey@gatech.edu>
parents: 3778
diff changeset
   148
  void CancelAllTimers();
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   149
  // attribute related
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   150
  virtual void SetSndBufSize (uint32_t size);
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   151
  virtual uint32_t GetSndBufSize (void) const;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   152
  virtual void SetRcvBufSize (uint32_t size);
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   153
  virtual uint32_t GetRcvBufSize (void) const;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   154
  virtual void SetSegSize (uint32_t size);
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   155
  virtual uint32_t GetSegSize (void) const;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   156
  virtual void SetSSThresh (uint32_t threshold);
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   157
  virtual uint32_t GetSSThresh (void) const;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   158
  virtual void SetInitialCwnd (uint32_t cwnd);
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   159
  virtual uint32_t GetInitialCwnd (void) const;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   160
  virtual void SetConnTimeout (Time timeout);
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   161
  virtual Time GetConnTimeout (void) const;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   162
  virtual void SetConnCount (uint32_t count);
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   163
  virtual uint32_t GetConnCount (void) const;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   164
  virtual void SetDelAckTimeout (Time timeout);
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   165
  virtual Time GetDelAckTimeout (void) const;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   166
  virtual void SetDelAckMaxCount (uint32_t count);
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   167
  virtual uint32_t GetDelAckMaxCount (void) const;
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   168
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
  bool m_skipRetxResched;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   170
  uint32_t m_dupAckCount;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   171
  EventId m_retxEvent;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   172
  EventId m_lastAckEvent;
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
  EventId m_delAckEvent;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   175
  uint32_t m_delAckCount;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   176
  uint32_t m_delAckMaxCount;
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   177
  Time m_delAckTimeout;
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   178
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   179
  Ipv4EndPoint *m_endPoint;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   180
  Ptr<Node> m_node;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   181
  Ptr<TcpL4Protocol> m_tcp;
5971
805783c866fc Bug 748 - Cloned TCP socket uses wrong source address
Fabian Mauchle <f1mauchl@hsr.ch>
parents: 5856
diff changeset
   182
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   183
  enum SocketErrno m_errno;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   184
  bool m_shutdownSend;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   185
  bool m_shutdownRecv;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   186
  bool m_connected;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   187
  
6273
8d70de29d514 spell check, mostly in comments.
Andrey Mazo <mazo@iitp.ru>
parents: 5971
diff changeset
   188
  //manage the state information
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   189
  States_t m_state;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   190
  bool m_closeNotified;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   191
  bool m_closeRequestNotified;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   192
  bool m_closeOnEmpty;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   193
  bool m_pendingClose;
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
  
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   196
  //sequence info, sender side
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   197
  SequenceNumber m_nextTxSequence;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   198
  SequenceNumber m_highTxMark;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   199
  SequenceNumber m_highestRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   200
  SequenceNumber m_lastRxAck;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   201
  
6273
8d70de29d514 spell check, mostly in comments.
Andrey Mazo <mazo@iitp.ru>
parents: 5971
diff changeset
   202
  //sequence info, receiver side
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   203
  SequenceNumber m_nextRxSequence; //next expected sequence
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   204
6328
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
   205
  //sequence number where fin was sent or received
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
   206
  SequenceNumber m_finSequence;
f03f4d82daaf Bug 902 - TCP: handle out-of-order packets during connection shutdown
Antti Mäkelä <zarhan@cc.hut.fi>
parents: 6273
diff changeset
   207
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   208
  //Rx buffer
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   209
  UnAckData_t m_bufferedData; //buffer which sorts out of sequence data
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   210
  //Rx buffer state
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   211
  uint32_t m_rxAvailable; // amount of data available for reading through Recv
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   212
  uint32_t m_rxBufSize; //size in bytes of the data in the rx buf
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   213
  //note that these two are not the same: rxAvailbale is the number of
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   214
  //contiguous sequenced bytes that can be read, rxBufSize is the TOTAL size
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   215
  //including out of sequence data, such that m_rxAvailable <= m_rxBufSize
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   216
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   217
  //this is kind of the tx buffer
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   218
  PendingData* m_pendingData;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   219
  SequenceNumber m_firstPendingSequence;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   221
  // Window management
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   222
  uint32_t                       m_segmentSize;          //SegmentSize
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   223
  uint32_t                       m_rxWindowSize;         //Flow control window
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   224
  TracedValue<uint32_t>          m_cWnd;                 //Congestion window
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   225
  uint32_t                       m_ssThresh;             //Slow Start Threshold
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   226
  uint32_t                       m_initialCWnd;          //Initial cWnd value
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   227
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   228
  //persist timer management
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   229
  Time                           m_persistTime;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   230
  EventId                        m_persistEvent;
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   231
  
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   232
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   233
  // Round trip time estimation
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   234
  Ptr<RttEstimator> m_rtt;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   235
  Time m_lastMeasuredRtt;
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   236
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   237
  // Timer-related members
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   238
  Time              m_cnTimeout; 
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   239
  uint32_t          m_cnCount;
3244
dbf56f98a11d Fix tcp rx buffer semantics; fromaddress tagging is broken at the moment
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3136
diff changeset
   240
3136
a59b9ce95b6b Move Tcp attributes from factory to TcpSocket
Tom Henderson <tomh@tomh.org>
parents: 3134
diff changeset
   241
  // Attributes
3252
5c53412347ac Fix compile warning
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3244
diff changeset
   242
  uint32_t m_sndBufSize;   // buffer limit for the outgoing queue
3644
5d836ab1523b Implement TCP finite rx buffer (bug 239)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3493
diff changeset
   243
  uint32_t m_rxBufMaxSize;   // maximum receive socket buffer size
3131
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
};
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   245
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   246
}//namespace ns3
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   247
d82336dfd269 change TcpSocket to TcpSocketImpl
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
#endif /* TCP_SOCKET_IMPL_H */