src/internet/model/pending-data.h
author Tom Henderson <tomh@tomh.org>
Fri, 25 Feb 2011 10:32:35 -0800
changeset 6834 036f9a0b9899
parent 6434 src/internet-stack/pending-data.h@ac8b4bf77e50
child 7176 9f2663992e99
permissions -rw-r--r--
Rename internet-stack to internet, and organize module
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     2
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     3
// Copyright (c) 2006 Georgia Tech Research Corporation
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     4
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     5
// This program is free software; you can redistribute it and/or modify
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     6
// it under the terms of the GNU General Public License version 2 as
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     7
// published by the Free Software Foundation;
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     8
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    12
// GNU General Public License for more details.
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    13
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    17
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    18
// Author: Rajib Bhattacharjea<raj.b@gatech.edu>
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    19
//
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    20
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    21
// Georgia Tech Network Simulator - Data Descriptors
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    22
// George F. Riley.  Georgia Tech, Spring 2002
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    23
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    24
#ifndef __datapdu_h__
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    25
#define __datapdu_h__
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    26
3249
a7203cfb5f37 Tcp tx buffer (pendingdata) uses Ptr<Packet> internally; tagging should work
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
    27
#include "ns3/packet.h"
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    28
#include "pending-data.h"
6434
ac8b4bf77e50 Bug 385 - Add a generic "sequence number" class.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6163
diff changeset
    29
#include "ns3/sequence-number.h"
2354
ba9d1cad1a7c Fix memory leaks in PendingData class by returning Ptr<Packet> instead of PendingData* where appropriate
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2224
diff changeset
    30
ba9d1cad1a7c Fix memory leaks in PendingData class by returning Ptr<Packet> instead of PendingData* where appropriate
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2224
diff changeset
    31
#include "ns3/ptr.h"
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    32
namespace ns3
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    33
{
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    34
class Packet;
3266
1ae7df5cf87b Update the internet-stack documentation
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3260
diff changeset
    35
3691
372f4475dc47 Doxygen for internet-stack
Tom Henderson <tomh@tomh.org>
parents: 3266
diff changeset
    36
/**
372f4475dc47 Doxygen for internet-stack
Tom Henderson <tomh@tomh.org>
parents: 3266
diff changeset
    37
 * \ingroup tcp
372f4475dc47 Doxygen for internet-stack
Tom Henderson <tomh@tomh.org>
parents: 3266
diff changeset
    38
 *
372f4475dc47 Doxygen for internet-stack
Tom Henderson <tomh@tomh.org>
parents: 3266
diff changeset
    39
 * \brief class for managing I/O between applications and TCP
372f4475dc47 Doxygen for internet-stack
Tom Henderson <tomh@tomh.org>
parents: 3266
diff changeset
    40
 */
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    41
class PendingData {
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    42
public:
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    43
  PendingData ();
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    44
  PendingData (uint32_t s, uint8_t* d = NULL, uint32_t msg = 0, uint32_t resp = 0);
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    45
  PendingData (const std::string&); // Construct from string
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    46
  PendingData (uint8_t*, uint32_t&, Packet*); // Construct from serialized buffer
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    47
  PendingData (const PendingData&);   // Copy constructor
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    48
  virtual ~PendingData ();     // Destructor
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    49
  uint32_t Size () const { return size;}
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    50
  // Serialization
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    51
  uint8_t*  Serialize (uint8_t*, uint32_t&); // Serialize to a buffer
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    52
  uint8_t*  Construct (uint8_t*, uint32_t&); // Construct from buffer
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    53
  virtual void Clear ();// Remove all associated data
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    54
  virtual void Add (uint32_t s, const uint8_t* d = 0);// Add some data to end
3250
464a2a2690e8 Update tcpsocket to use Ptr<Packet> in Send
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3249
diff changeset
    55
  virtual void Add (Ptr<Packet> p);
6161
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    56
  /**
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    57
   * This method returns the number of bytes in the PendingData buffer
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    58
   * beyond the sequence number specified by seqOffset.
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    59
   *
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    60
   * The variables seqFront and seqOffset correspond to a sequence number
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    61
   * space in use by the user.  What is significant in this method is the
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    62
   * difference between them; i.e. the quantity (seqOffset - seqFront). 
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    63
   * This difference is subtracted from Size(), yielding the number of
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    64
   * bytes beyond seqOffset, from the user perspective, in the PendingData
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    65
   * buffer.
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    66
   *
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    67
   * If the first number specified is not a sequence number that corresponds
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    68
   * to the first data byte in the PendingData buffer, the computation
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    69
   * returned will be in error.
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    70
   * 
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    71
   * \return number of bytes 
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    72
   * \param seqFront sequence number of assumed first byte in the PendingData
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    73
   * \param seqOffset sequence number of offset 
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    74
   */
6434
ac8b4bf77e50 Bug 385 - Add a generic "sequence number" class.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6163
diff changeset
    75
  virtual uint32_t SizeFromSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    76
  // Inquire available data from offset
6161
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    77
  /**
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    78
   * \return number of bytes in the data buffer beyond the offset specified
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    79
   * \param offset offset (from zero) 
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    80
   */
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    81
  virtual uint32_t SizeFromOffset (uint32_t offset);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    82
  // Available size from sequence difference 
6161
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    83
  /**
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    84
   * Subtracts seqFront from seqOffset after enforcing seqFront is less
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    85
   * than seqOffset
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    86
   *
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    87
   * \param seqFront sequence number to be subtracted from seqOffset
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    88
   * \param seqOffset higher sequence number
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    89
   * \return seqOffset-seqFront
c52406de004d some doxygen
Tom Henderson <tomh@tomh.org>
parents: 4741
diff changeset
    90
   */
6434
ac8b4bf77e50 Bug 385 - Add a generic "sequence number" class.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6163
diff changeset
    91
  virtual uint32_t OffsetFromSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset);
2354
ba9d1cad1a7c Fix memory leaks in PendingData class by returning Ptr<Packet> instead of PendingData* where appropriate
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2224
diff changeset
    92
  virtual Ptr<Packet> CopyFromOffset (uint32_t, uint32_t);  // Size, offset, ret packet
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
    93
  // Copy data, size, offset specified by sequence difference
6434
ac8b4bf77e50 Bug 385 - Add a generic "sequence number" class.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6163
diff changeset
    94
  virtual Ptr<Packet> CopyFromSeq (uint32_t, const SequenceNumber32&, const SequenceNumber32&);
6163
cdabef59da08 Bug 829 - TCP unbound memory problem (pending data)
Josh Pelkey <jpelkey@gatech.edu>
parents: 6161
diff changeset
    95
  /**
cdabef59da08 Bug 829 - TCP unbound memory problem (pending data)
Josh Pelkey <jpelkey@gatech.edu>
parents: 6161
diff changeset
    96
   * Permits object to clear any pending data between seqFront and 
cdabef59da08 Bug 829 - TCP unbound memory problem (pending data)
Josh Pelkey <jpelkey@gatech.edu>
parents: 6161
diff changeset
    97
   * seqOffset - 1).  Callers should check the return value to determine
cdabef59da08 Bug 829 - TCP unbound memory problem (pending data)
Josh Pelkey <jpelkey@gatech.edu>
parents: 6161
diff changeset
    98
   * whether any data was removed from the front.
cdabef59da08 Bug 829 - TCP unbound memory problem (pending data)
Josh Pelkey <jpelkey@gatech.edu>
parents: 6161
diff changeset
    99
   *
cdabef59da08 Bug 829 - TCP unbound memory problem (pending data)
Josh Pelkey <jpelkey@gatech.edu>
parents: 6161
diff changeset
   100
   * \param seqFront sequence number to start to try to remove from 
cdabef59da08 Bug 829 - TCP unbound memory problem (pending data)
Josh Pelkey <jpelkey@gatech.edu>
parents: 6161
diff changeset
   101
   * \param seqOffset first sequence number in buffer that should be retained
cdabef59da08 Bug 829 - TCP unbound memory problem (pending data)
Josh Pelkey <jpelkey@gatech.edu>
parents: 6161
diff changeset
   102
   * \return number of bytes from the front that were removed from the buffer
cdabef59da08 Bug 829 - TCP unbound memory problem (pending data)
Josh Pelkey <jpelkey@gatech.edu>
parents: 6161
diff changeset
   103
   */
6434
ac8b4bf77e50 Bug 385 - Add a generic "sequence number" class.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6163
diff changeset
   104
  virtual uint32_t RemoveToSeq (const SequenceNumber32& seqFront, const SequenceNumber32& seqOffset);
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   105
  PendingData*   Copy () const;          // Create a copy of this header
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   106
  PendingData*   CopyS (uint32_t);         // Copy with new size
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   107
  PendingData*   CopySD (uint32_t, uint8_t*); // Copy with new size, new data
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   108
public:
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   109
  uint32_t size;        // Number of data bytes
3249
a7203cfb5f37 Tcp tx buffer (pendingdata) uses Ptr<Packet> internally; tagging should work
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 2834
diff changeset
   110
  std::vector<Ptr<Packet> > data;         // Corresponding data (may be null)
2224
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   111
  // The next two fields allow simulated applications to exchange some info
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   112
  uint32_t msgSize;     // Total size of message
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   113
  uint32_t responseSize;// Size of response requested
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   114
};
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   115
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   116
}//namepsace ns3
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   117
#endif
6f97d21a99c2 Added in ns-3-tcp (second try)
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
diff changeset
   118