src/internet/model/tcp-socket-base.cc
author Tom Henderson <tomh@tomh.org>
Mon, 04 May 2015 22:39:00 -0700
changeset 11362 917793d13817
parent 11359 c2269e7c4f42
child 11500 366c7284d4a8
permissions -rw-r--r--
bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents: 7256
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     2
/*
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
     3
 * Copyright (c) 2007 Georgia Tech Research Corporation
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     4
 * Copyright (c) 2010 Adrian Sai-wah Tam
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     5
 *
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
     9
 *
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    13
 * GNU General Public License for more details.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    14
 *
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    18
 *
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    19
 * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    20
 */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    21
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    22
#define NS_LOG_APPEND_CONTEXT \
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    23
  if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    24
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    25
#include "ns3/abort.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    26
#include "ns3/node.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    27
#include "ns3/inet-socket-address.h"
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
    28
#include "ns3/inet6-socket-address.h"
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    29
#include "ns3/log.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    30
#include "ns3/ipv4.h"
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
    31
#include "ns3/ipv6.h"
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    32
#include "ns3/ipv4-interface-address.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    33
#include "ns3/ipv4-route.h"
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
    34
#include "ns3/ipv6-route.h"
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    35
#include "ns3/ipv4-routing-protocol.h"
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
    36
#include "ns3/ipv6-routing-protocol.h"
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    37
#include "ns3/simulation-singleton.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    38
#include "ns3/simulator.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    39
#include "ns3/packet.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    40
#include "ns3/uinteger.h"
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    41
#include "ns3/double.h"
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
    42
#include "ns3/pointer.h"
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    43
#include "ns3/trace-source-accessor.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    44
#include "tcp-socket-base.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    45
#include "tcp-l4-protocol.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    46
#include "ipv4-end-point.h"
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
    47
#include "ipv6-end-point.h"
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
    48
#include "ipv6-l3-protocol.h"
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    49
#include "tcp-header.h"
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    50
#include "tcp-option-winscale.h"
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    51
#include "tcp-option-ts.h"
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    52
#include "rtt-estimator.h"
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    53
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    54
#include <math.h>
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    55
#include <algorithm>
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    56
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10943
diff changeset
    57
namespace ns3 {
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    58
10968
2d29fee2b7b8 [Bug 1551] Redux: NS_LOG_COMPONENT_DEFINE inside or outside of ns3 namespace?
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10943
diff changeset
    59
NS_LOG_COMPONENT_DEFINE ("TcpSocketBase");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    60
10652
dc18deba4502 [doxygen] Revert r10410, r10411, r10412
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10594
diff changeset
    61
NS_OBJECT_ENSURE_REGISTERED (TcpSocketBase);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    62
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    63
TypeId
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    64
TcpSocketBase::GetTypeId (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    65
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    66
  static TypeId tid = TypeId ("ns3::TcpSocketBase")
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    67
    .SetParent<TcpSocket> ()
11259
ea2f6a3ed14e SetGroupName for internet module
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11231
diff changeset
    68
    .SetGroupName ("Internet")
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    69
//    .AddAttribute ("TcpState", "State in TCP state machine",
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    70
//                   TypeId::ATTR_GET,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    71
//                   EnumValue (CLOSED),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    72
//                   MakeEnumAccessor (&TcpSocketBase::m_state),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
    73
//                   MakeEnumChecker (CLOSED, "Closed"))
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    74
    .AddAttribute ("MaxSegLifetime",
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    75
                   "Maximum segment lifetime in seconds, use for TIME_WAIT state transition to CLOSED state",
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    76
                   DoubleValue (120), /* RFC793 says MSL=2 minutes*/
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    77
                   MakeDoubleAccessor (&TcpSocketBase::m_msl),
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    78
                   MakeDoubleChecker<double> (0))
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    79
    .AddAttribute ("MaxWindowSize", "Max size of advertised window",
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    80
                   UintegerValue (65535),
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    81
                   MakeUintegerAccessor (&TcpSocketBase::m_maxWinSize),
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
    82
                   MakeUintegerChecker<uint16_t> ())
9095
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
    83
    .AddAttribute ("IcmpCallback", "Callback invoked whenever an icmp error is received on this socket.",
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
    84
                   CallbackValue (),
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
    85
                   MakeCallbackAccessor (&TcpSocketBase::m_icmpCallback),
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
    86
                   MakeCallbackChecker ())
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
    87
    .AddAttribute ("IcmpCallback6", "Callback invoked whenever an icmpv6 error is received on this socket.",
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
    88
                   CallbackValue (),
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
    89
                   MakeCallbackAccessor (&TcpSocketBase::m_icmpCallback6),
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    90
                   MakeCallbackChecker ())
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    91
    .AddAttribute ("WindowScaling", "Enable or disable Window Scaling option",
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    92
                   BooleanValue (true),
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    93
                   MakeBooleanAccessor (&TcpSocketBase::m_winScalingEnabled),
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    94
                   MakeBooleanChecker ())
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    95
    .AddAttribute ("Timestamp", "Enable or disable Timestamp option",
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    96
                   BooleanValue (true),
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    97
                   MakeBooleanAccessor (&TcpSocketBase::m_timestampEnabled),
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
    98
                   MakeBooleanChecker ())
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
    99
    .AddAttribute ("MinRto",
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   100
                   "Minimum retransmit timeout value",
11231
62ce11a18acd Bug 2076 - TCP MinRTO Attribute is not actually used
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11202
diff changeset
   101
                   TimeValue (Seconds (1.0)), // RFC 6298 says min RTO=1 sec, but Linux uses 200ms. See http://www.postel.org/pipermail/end2end-interest/2004-November/004402.html
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   102
                   MakeTimeAccessor (&TcpSocketBase::SetMinRto,
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   103
                                     &TcpSocketBase::GetMinRto),
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   104
                                     MakeTimeChecker ())
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   105
    .AddAttribute ("ClockGranularity",
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   106
                   "Clock Granularity used in RTO calculations",
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   107
                   TimeValue (MilliSeconds (1)), // RFC6298 suggest to use fine clock granularity
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   108
                   MakeTimeAccessor (&TcpSocketBase::SetClockGranularity,
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   109
                                     &TcpSocketBase::GetClockGranularity),
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   110
                                     MakeTimeChecker ())
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   111
    .AddAttribute ("TxBuffer",
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   112
                   "TCP Tx buffer",
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   113
                   PointerValue (),
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   114
                   MakePointerAccessor (&TcpSocketBase::GetTxBuffer),
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   115
                                       MakePointerChecker<TcpTxBuffer> ())
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   116
    .AddAttribute ("RxBuffer",
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   117
                   "TCP Rx buffer",
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   118
                   PointerValue (),
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   119
                   MakePointerAccessor (&TcpSocketBase::GetRxBuffer),
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   120
                   MakePointerChecker<TcpRxBuffer> ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   121
    .AddTraceSource ("RTO",
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   122
                     "Retransmission timeout",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   123
                     MakeTraceSourceAccessor (&TcpSocketBase::m_rto),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   124
                     "ns3::Time::TracedValueCallback")
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   125
    .AddTraceSource ("RTT",
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   126
                     "Last RTT sample",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   127
                     MakeTraceSourceAccessor (&TcpSocketBase::m_lastRtt),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   128
                     "ns3::Time::TracedValueCallback")
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   129
    .AddTraceSource ("NextTxSequence",
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   130
                     "Next sequence number to send (SND.NXT)",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   131
                     MakeTraceSourceAccessor (&TcpSocketBase::m_nextTxSequence),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   132
                     "ns3::SequenceNumber32TracedValueCallback")
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   133
    .AddTraceSource ("HighestSequence",
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   134
                     "Highest sequence number ever sent in socket's life time",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   135
                     MakeTraceSourceAccessor (&TcpSocketBase::m_highTxMark),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   136
                     "ns3::SequenceNumber32TracedValueCallback")
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   137
    .AddTraceSource ("State",
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   138
                     "TCP state",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   139
                     MakeTraceSourceAccessor (&TcpSocketBase::m_state),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   140
                     "ns3::TcpStatesTracedValueCallback")
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   141
    .AddTraceSource ("RWND",
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   142
                     "Remote side's flow control window",
10978
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   143
                     MakeTraceSourceAccessor (&TcpSocketBase::m_rWnd),
754c8256c35c TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 10968
diff changeset
   144
                     "ns3::TracedValue::Uint32Callback")
11362
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   145
    .AddTraceSource ("HighestRxSequence",
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   146
                     "Highest sequence number received from peer",
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   147
                     MakeTraceSourceAccessor (&TcpSocketBase::m_highRxMark),
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   148
                     "ns3::SequenceNumber32TracedValueCallback")
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   149
    .AddTraceSource ("HighestRxAck",
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   150
                     "Highest ack received from peer",
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   151
                     MakeTraceSourceAccessor (&TcpSocketBase::m_highRxAckMark),
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   152
                     "ns3::SequenceNumber32TracedValueCallback")
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   153
  ;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   154
  return tid;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   155
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   156
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   157
TcpSocketBase::TcpSocketBase (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   158
  : m_dupAckCount (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   159
    m_delAckCount (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   160
    m_endPoint (0),
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   161
    m_endPoint6 (0),
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   162
    m_node (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   163
    m_tcp (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   164
    m_rtt (0),
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   165
    m_nextTxSequence (0),
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   166
    // Change this for non-zero initial sequence number
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   167
    m_highTxMark (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   168
    m_rxBuffer (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   169
    m_txBuffer (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   170
    m_state (CLOSED),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   171
    m_errno (ERROR_NOTERROR),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   172
    m_closeNotified (false),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   173
    m_closeOnEmpty (false),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   174
    m_shutdownSend (false),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   175
    m_shutdownRecv (false),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   176
    m_connected (false),
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   177
    m_segmentSize (0),
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   178
    // For attribute initialization consistency (quiet valgrind)
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
   179
    m_rWnd (0),
11362
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   180
    m_highRxMark (0),
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   181
    m_highRxAckMark (0),
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
   182
    m_sndScaleFactor (0),
10907
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   183
    m_rcvScaleFactor (0),
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   184
    m_timestampEnabled (true),
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   185
    m_timestampToEcho (0)
10907
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   186
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   187
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   188
  NS_LOG_FUNCTION (this);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   189
  m_rxBuffer = CreateObject<TcpRxBuffer> ();
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   190
  m_txBuffer = CreateObject<TcpTxBuffer> ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   191
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   192
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   193
TcpSocketBase::TcpSocketBase (const TcpSocketBase& sock)
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   194
  : TcpSocket (sock),
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   195
    //copy object::m_tid and socket::callbacks
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   196
    m_dupAckCount (sock.m_dupAckCount),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   197
    m_delAckCount (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   198
    m_delAckMaxCount (sock.m_delAckMaxCount),
7619
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
   199
    m_noDelay (sock.m_noDelay),
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   200
    m_cnRetries (sock.m_cnRetries),
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   201
    m_delAckTimeout (sock.m_delAckTimeout),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   202
    m_persistTimeout (sock.m_persistTimeout),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   203
    m_cnTimeout (sock.m_cnTimeout),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   204
    m_endPoint (0),
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   205
    m_endPoint6 (0),
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   206
    m_node (sock.m_node),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   207
    m_tcp (sock.m_tcp),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   208
    m_rtt (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   209
    m_nextTxSequence (sock.m_nextTxSequence),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   210
    m_highTxMark (sock.m_highTxMark),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   211
    m_state (sock.m_state),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   212
    m_errno (sock.m_errno),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   213
    m_closeNotified (sock.m_closeNotified),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   214
    m_closeOnEmpty (sock.m_closeOnEmpty),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   215
    m_shutdownSend (sock.m_shutdownSend),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   216
    m_shutdownRecv (sock.m_shutdownRecv),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   217
    m_connected (sock.m_connected),
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   218
    m_msl (sock.m_msl),
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   219
    m_segmentSize (sock.m_segmentSize),
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   220
    m_maxWinSize (sock.m_maxWinSize),
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
   221
    m_rWnd (sock.m_rWnd),
11362
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   222
    m_highRxMark (sock.m_highRxMark),
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   223
    m_highRxAckMark (sock.m_highRxAckMark),
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
   224
    m_winScalingEnabled (sock.m_winScalingEnabled),
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
   225
    m_sndScaleFactor (sock.m_sndScaleFactor),
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
   226
    m_rcvScaleFactor (sock.m_rcvScaleFactor),
10907
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   227
    m_timestampEnabled (sock.m_timestampEnabled),
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   228
    m_timestampToEcho (sock.m_timestampToEcho)
10907
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   229
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   230
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   231
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   232
  NS_LOG_LOGIC ("Invoked the copy constructor");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   233
  // Copy the rtt estimator if it is set
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   234
  if (sock.m_rtt)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   235
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   236
      m_rtt = sock.m_rtt->Copy ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   237
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   238
  // Reset all callbacks to null
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   239
  Callback<void, Ptr< Socket > > vPS = MakeNullCallback<void, Ptr<Socket> > ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   240
  Callback<void, Ptr<Socket>, const Address &> vPSA = MakeNullCallback<void, Ptr<Socket>, const Address &> ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   241
  Callback<void, Ptr<Socket>, uint32_t> vPSUI = MakeNullCallback<void, Ptr<Socket>, uint32_t> ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   242
  SetConnectCallback (vPS, vPS);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   243
  SetDataSentCallback (vPSUI);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   244
  SetSendCallback (vPSUI);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   245
  SetRecvCallback (vPS);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   246
  m_txBuffer = CopyObject (sock.m_txBuffer);
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   247
  m_rxBuffer = CopyObject (sock.m_rxBuffer);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   248
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   249
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   250
TcpSocketBase::~TcpSocketBase (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   251
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   252
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   253
  m_node = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   254
  if (m_endPoint != 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   255
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   256
      NS_ASSERT (m_tcp != 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   257
      /*
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   258
       * Upon Bind, an Ipv4Endpoint is allocated and set to m_endPoint, and
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   259
       * DestroyCallback is set to TcpSocketBase::Destroy. If we called
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   260
       * m_tcp->DeAllocate, it wil destroy its Ipv4EndpointDemux::DeAllocate,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   261
       * which in turn destroys my m_endPoint, and in turn invokes
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   262
       * TcpSocketBase::Destroy to nullify m_node, m_endPoint, and m_tcp.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   263
       */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   264
      NS_ASSERT (m_endPoint != 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   265
      m_tcp->DeAllocate (m_endPoint);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   266
      NS_ASSERT (m_endPoint == 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   267
    }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   268
  if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   269
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   270
      NS_ASSERT (m_tcp != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   271
      NS_ASSERT (m_endPoint6 != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   272
      m_tcp->DeAllocate (m_endPoint6);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   273
      NS_ASSERT (m_endPoint6 == 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   274
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   275
  m_tcp = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   276
  CancelAllTimers ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   277
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   278
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   279
/* Associate a node with this TCP socket */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   280
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   281
TcpSocketBase::SetNode (Ptr<Node> node)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   282
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   283
  m_node = node;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   284
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   285
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   286
/* Associate the L4 protocol (e.g. mux/demux) with this socket */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   287
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   288
TcpSocketBase::SetTcp (Ptr<TcpL4Protocol> tcp)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   289
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   290
  m_tcp = tcp;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   291
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   292
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   293
/* Set an RTT estimator with this socket */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   294
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   295
TcpSocketBase::SetRtt (Ptr<RttEstimator> rtt)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   296
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   297
  m_rtt = rtt;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   298
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   299
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   300
/* Inherit from Socket class: Returns error code */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   301
enum Socket::SocketErrno
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   302
TcpSocketBase::GetErrno (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   303
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   304
  return m_errno;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   305
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   306
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   307
/* Inherit from Socket class: Returns socket type, NS3_SOCK_STREAM */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   308
enum Socket::SocketType
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   309
TcpSocketBase::GetSocketType (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   310
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   311
  return NS3_SOCK_STREAM;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   312
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   313
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   314
/* Inherit from Socket class: Returns associated node */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   315
Ptr<Node>
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   316
TcpSocketBase::GetNode (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   317
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   318
  NS_LOG_FUNCTION_NOARGS ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   319
  return m_node;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   320
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   321
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   322
/* Inherit from Socket class: Bind socket to an end-point in TcpL4Protocol */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   323
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   324
TcpSocketBase::Bind (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   325
{
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   326
  NS_LOG_FUNCTION (this);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   327
  m_endPoint = m_tcp->Allocate ();
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   328
  if (0 == m_endPoint)
7441
bf446d9feecc Bug 1163 - Ipv4EndPointDemux::AllocateEphemeralPort forget to increment the port
John Abraham <john.abraham@gatech.edu>
parents: 7440
diff changeset
   329
    {
bf446d9feecc Bug 1163 - Ipv4EndPointDemux::AllocateEphemeralPort forget to increment the port
John Abraham <john.abraham@gatech.edu>
parents: 7440
diff changeset
   330
      m_errno = ERROR_ADDRNOTAVAIL;
bf446d9feecc Bug 1163 - Ipv4EndPointDemux::AllocateEphemeralPort forget to increment the port
John Abraham <john.abraham@gatech.edu>
parents: 7440
diff changeset
   331
      return -1;
bf446d9feecc Bug 1163 - Ipv4EndPointDemux::AllocateEphemeralPort forget to increment the port
John Abraham <john.abraham@gatech.edu>
parents: 7440
diff changeset
   332
    }
10697
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   333
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   334
  if (std::find(m_tcp->m_sockets.begin(), m_tcp->m_sockets.end(), this) == m_tcp->m_sockets.end())
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   335
    {
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   336
      m_tcp->m_sockets.push_back (this);
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   337
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   338
  return SetupCallback ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   339
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   340
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   341
int
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   342
TcpSocketBase::Bind6 (void)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   343
{
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   344
  NS_LOG_FUNCTION (this);
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   345
  m_endPoint6 = m_tcp->Allocate6 ();
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   346
  if (0 == m_endPoint6)
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   347
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   348
      m_errno = ERROR_ADDRNOTAVAIL;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   349
      return -1;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   350
    }
10697
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   351
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   352
  if (std::find(m_tcp->m_sockets.begin(), m_tcp->m_sockets.end(), this) == m_tcp->m_sockets.end())
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   353
    {
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   354
      m_tcp->m_sockets.push_back (this);
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   355
    }
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   356
  return SetupCallback ();
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   357
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   358
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   359
/* Inherit from Socket class: Bind socket (with specific address) to an end-point in TcpL4Protocol */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   360
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   361
TcpSocketBase::Bind (const Address &address)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   362
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   363
  NS_LOG_FUNCTION (this << address);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   364
  if (InetSocketAddress::IsMatchingType (address))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   365
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   366
      InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   367
      Ipv4Address ipv4 = transport.GetIpv4 ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   368
      uint16_t port = transport.GetPort ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   369
      if (ipv4 == Ipv4Address::GetAny () && port == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   370
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   371
          m_endPoint = m_tcp->Allocate ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   372
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   373
      else if (ipv4 == Ipv4Address::GetAny () && port != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   374
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   375
          m_endPoint = m_tcp->Allocate (port);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   376
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   377
      else if (ipv4 != Ipv4Address::GetAny () && port == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   378
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   379
          m_endPoint = m_tcp->Allocate (ipv4);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   380
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   381
      else if (ipv4 != Ipv4Address::GetAny () && port != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   382
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   383
          m_endPoint = m_tcp->Allocate (ipv4, port);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   384
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   385
      if (0 == m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   386
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   387
          m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   388
          return -1;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   389
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   390
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   391
  else if (Inet6SocketAddress::IsMatchingType (address))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   392
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   393
      Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   394
      Ipv6Address ipv6 = transport.GetIpv6 ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   395
      uint16_t port = transport.GetPort ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   396
      if (ipv6 == Ipv6Address::GetAny () && port == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   397
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   398
          m_endPoint6 = m_tcp->Allocate6 ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   399
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   400
      else if (ipv6 == Ipv6Address::GetAny () && port != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   401
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   402
          m_endPoint6 = m_tcp->Allocate6 (port);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   403
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   404
      else if (ipv6 != Ipv6Address::GetAny () && port == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   405
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   406
          m_endPoint6 = m_tcp->Allocate6 (ipv6);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   407
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   408
      else if (ipv6 != Ipv6Address::GetAny () && port != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   409
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   410
          m_endPoint6 = m_tcp->Allocate6 (ipv6, port);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   411
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   412
      if (0 == m_endPoint6)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   413
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   414
          m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   415
          return -1;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   416
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   417
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   418
  else
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   419
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   420
      m_errno = ERROR_INVAL;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   421
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   422
    }
10697
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   423
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   424
  if (std::find(m_tcp->m_sockets.begin(), m_tcp->m_sockets.end(), this) == m_tcp->m_sockets.end())
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   425
    {
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   426
      m_tcp->m_sockets.push_back (this);
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   427
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   428
  NS_LOG_LOGIC ("TcpSocketBase " << this << " got an endpoint: " << m_endPoint);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   429
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   430
  return SetupCallback ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   431
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   432
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   433
/* Inherit from Socket class: Initiate connection to a remote address:port */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   434
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   435
TcpSocketBase::Connect (const Address & address)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   436
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   437
  NS_LOG_FUNCTION (this << address);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   438
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   439
  // If haven't do so, Bind() this socket first
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   440
  if (InetSocketAddress::IsMatchingType (address) && m_endPoint6 == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   441
    {
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   442
      if (m_endPoint == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   443
        {
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   444
          if (Bind () == -1)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   445
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   446
              NS_ASSERT (m_endPoint == 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   447
              return -1; // Bind() failed
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   448
            }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   449
          NS_ASSERT (m_endPoint != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   450
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   451
      InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   452
      m_endPoint->SetPeer (transport.GetIpv4 (), transport.GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   453
      m_endPoint6 = 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   454
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   455
      // Get the appropriate local address and port number from the routing protocol and set up endpoint
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   456
      if (SetupEndpoint () != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   457
        { // Route to destination does not exist
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   458
          return -1;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   459
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   460
    }
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   461
  else if (Inet6SocketAddress::IsMatchingType (address)  && m_endPoint == 0)
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   462
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   463
      // If we are operating on a v4-mapped address, translate the address to
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   464
      // a v4 address and re-call this function
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   465
      Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   466
      Ipv6Address v6Addr = transport.GetIpv6 ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   467
      if (v6Addr.IsIpv4MappedAddress () == true)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   468
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   469
          Ipv4Address v4Addr = v6Addr.GetIpv4MappedAddress ();
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   470
          return Connect (InetSocketAddress (v4Addr, transport.GetPort ()));
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   471
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   472
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   473
      if (m_endPoint6 == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   474
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   475
          if (Bind6 () == -1)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   476
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   477
              NS_ASSERT (m_endPoint6 == 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   478
              return -1; // Bind() failed
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   479
            }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   480
          NS_ASSERT (m_endPoint6 != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   481
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   482
      m_endPoint6->SetPeer (v6Addr, transport.GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   483
      m_endPoint = 0;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   484
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   485
      // Get the appropriate local address and port number from the routing protocol and set up endpoint
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   486
      if (SetupEndpoint6 () != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   487
        { // Route to destination does not exist
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   488
          return -1;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   489
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   490
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   491
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   492
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   493
      m_errno = ERROR_INVAL;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   494
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   495
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   496
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   497
  // Re-initialize parameters in case this socket is being reused after CLOSE
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   498
  m_rtt->Reset ();
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   499
  m_cnCount = m_cnRetries;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   500
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   501
  // DoConnect() will do state-checking and send a SYN packet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   502
  return DoConnect ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   503
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   504
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   505
/* Inherit from Socket class: Listen on the endpoint for an incoming connection */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   506
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   507
TcpSocketBase::Listen (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   508
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   509
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   510
  // Linux quits EINVAL if we're not in CLOSED state, so match what they do
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   511
  if (m_state != CLOSED)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   512
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   513
      m_errno = ERROR_INVAL;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   514
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   515
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   516
  // In other cases, set the state to LISTEN and done
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   517
  NS_LOG_INFO ("CLOSED -> LISTEN");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   518
  m_state = LISTEN;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   519
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   520
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   521
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   522
/* Inherit from Socket class: Kill this socket and signal the peer (if any) */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   523
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   524
TcpSocketBase::Close (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   525
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   526
  NS_LOG_FUNCTION (this);
10157
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9258
diff changeset
   527
  /// \internal
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9258
diff changeset
   528
  /// First we check to see if there is any unread rx data.
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9258
diff changeset
   529
  /// \bugid{426} claims we should send reset in this case.
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   530
  if (m_rxBuffer->Size () != 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   531
    {
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   532
      NS_LOG_INFO ("Socket " << this << " << unread rx data during close.  Sending reset");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   533
      SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   534
      return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   535
    }
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   536
 
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   537
  if (m_txBuffer->SizeFromSequence (m_nextTxSequence) > 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   538
    { // App close with pending data must wait until all data transmitted
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   539
      if (m_closeOnEmpty == false)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   540
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   541
          m_closeOnEmpty = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   542
          NS_LOG_INFO ("Socket " << this << " deferring close, state " << TcpStateName[m_state]);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   543
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   544
      return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   545
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   546
  return DoClose ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   547
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   548
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   549
/* Inherit from Socket class: Signal a termination of send */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   550
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   551
TcpSocketBase::ShutdownSend (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   552
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   553
  NS_LOG_FUNCTION (this);
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   554
  
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   555
  //this prevents data from being added to the buffer
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   556
  m_shutdownSend = true;
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   557
  m_closeOnEmpty = true;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   558
  //if buffer is already empty, send a fin now
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   559
  //otherwise fin will go when buffer empties.
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   560
  if (m_txBuffer->Size () == 0)
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   561
    {
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   562
      if (m_state == ESTABLISHED || m_state == CLOSE_WAIT)
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   563
        {
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   564
          NS_LOG_INFO("Emtpy tx buffer, send fin");
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   565
          SendEmptyPacket (TcpHeader::FIN);  
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   566
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   567
          if (m_state == ESTABLISHED)
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   568
            { // On active close: I am the first one to send FIN
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   569
              NS_LOG_INFO ("ESTABLISHED -> FIN_WAIT_1");
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   570
              m_state = FIN_WAIT_1;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   571
            }
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   572
          else
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   573
            { // On passive close: Peer sent me FIN already
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   574
              NS_LOG_INFO ("CLOSE_WAIT -> LAST_ACK");
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   575
              m_state = LAST_ACK;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   576
            }  
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   577
        }
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   578
    }
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   579
 
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   580
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   581
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   582
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   583
/* Inherit from Socket class: Signal a termination of receive */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   584
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   585
TcpSocketBase::ShutdownRecv (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   586
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   587
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   588
  m_shutdownRecv = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   589
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   590
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   591
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   592
/* Inherit from Socket class: Send a packet. Parameter flags is not used.
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   593
    Packet has no TCP header. Invoked by upper-layer application */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   594
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   595
TcpSocketBase::Send (Ptr<Packet> p, uint32_t flags)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   596
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   597
  NS_LOG_FUNCTION (this << p);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   598
  NS_ABORT_MSG_IF (flags, "use of flags is not supported in TcpSocketBase::Send()");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   599
  if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   600
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   601
      // Store the packet into Tx buffer
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   602
      if (!m_txBuffer->Add (p))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   603
        { // TxBuffer overflow, send failed
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   604
          m_errno = ERROR_MSGSIZE;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   605
          return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   606
        }
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   607
      if (m_shutdownSend)
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   608
        {
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   609
          m_errno = ERROR_SHUTDOWN;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   610
          return -1;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   611
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   612
      // Submit the data to lower layers
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   613
      NS_LOG_LOGIC ("txBufSize=" << m_txBuffer->Size () << " state " << TcpStateName[m_state]);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   614
      if (m_state == ESTABLISHED || m_state == CLOSE_WAIT)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   615
        { // Try to send the data out
11359
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
   616
          if (!m_sendPendingDataEvent.IsRunning ())
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
   617
            {
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
   618
              m_sendPendingDataEvent = Simulator::Schedule ( TimeStep (1), &TcpSocketBase::SendPendingData, this, m_connected);
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
   619
            }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   620
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   621
      return p->GetSize ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   622
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   623
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   624
    { // Connection not established yet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   625
      m_errno = ERROR_NOTCONN;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   626
      return -1; // Send failure
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   627
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   628
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   629
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   630
/* Inherit from Socket class: In TcpSocketBase, it is same as Send() call */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   631
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   632
TcpSocketBase::SendTo (Ptr<Packet> p, uint32_t flags, const Address &address)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   633
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   634
  return Send (p, flags); // SendTo() and Send() are the same
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   635
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   636
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   637
/* Inherit from Socket class: Return data to upper-layer application. Parameter flags
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   638
   is not used. Data is returned as a packet of size no larger than maxSize */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   639
Ptr<Packet>
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   640
TcpSocketBase::Recv (uint32_t maxSize, uint32_t flags)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   641
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   642
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   643
  NS_ABORT_MSG_IF (flags, "use of flags is not supported in TcpSocketBase::Recv()");
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   644
  if (m_rxBuffer->Size () == 0 && m_state == CLOSE_WAIT)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   645
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   646
      return Create<Packet> (); // Send EOF on connection close
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   647
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   648
  Ptr<Packet> outPacket = m_rxBuffer->Extract (maxSize);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   649
  if (outPacket != 0 && outPacket->GetSize () != 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   650
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   651
      SocketAddressTag tag;
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   652
      if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   653
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   654
          tag.SetAddress (InetSocketAddress (m_endPoint->GetPeerAddress (), m_endPoint->GetPeerPort ()));
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   655
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   656
      else if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   657
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   658
          tag.SetAddress (Inet6SocketAddress (m_endPoint6->GetPeerAddress (), m_endPoint6->GetPeerPort ()));
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   659
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   660
      outPacket->AddPacketTag (tag);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   661
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   662
  return outPacket;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   663
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   664
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   665
/* Inherit from Socket class: Recv and return the remote's address */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   666
Ptr<Packet>
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   667
TcpSocketBase::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   668
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   669
  NS_LOG_FUNCTION (this << maxSize << flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   670
  Ptr<Packet> packet = Recv (maxSize, flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   671
  // Null packet means no data to read, and an empty packet indicates EOF
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   672
  if (packet != 0 && packet->GetSize () != 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   673
    {
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   674
      if (m_endPoint != 0)
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   675
        {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   676
          fromAddress = InetSocketAddress (m_endPoint->GetPeerAddress (), m_endPoint->GetPeerPort ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   677
        }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   678
      else if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   679
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   680
          fromAddress = Inet6SocketAddress (m_endPoint6->GetPeerAddress (), m_endPoint6->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   681
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   682
      else
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   683
        {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   684
          fromAddress = InetSocketAddress (Ipv4Address::GetZero (), 0);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   685
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   686
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   687
  return packet;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   688
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   689
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   690
/* Inherit from Socket class: Get the max number of bytes an app can send */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   691
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   692
TcpSocketBase::GetTxAvailable (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   693
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   694
  NS_LOG_FUNCTION (this);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   695
  return m_txBuffer->Available ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   696
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   697
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   698
/* Inherit from Socket class: Get the max number of bytes an app can read */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   699
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   700
TcpSocketBase::GetRxAvailable (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   701
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   702
  NS_LOG_FUNCTION (this);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   703
  return m_rxBuffer->Available ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   704
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   705
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   706
/* Inherit from Socket class: Return local address:port */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   707
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   708
TcpSocketBase::GetSockName (Address &address) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   709
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   710
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   711
  if (m_endPoint != 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   712
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   713
      address = InetSocketAddress (m_endPoint->GetLocalAddress (), m_endPoint->GetLocalPort ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   714
    }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   715
  else if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   716
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   717
      address = Inet6SocketAddress (m_endPoint6->GetLocalAddress (), m_endPoint6->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   718
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   719
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   720
    { // It is possible to call this method on a socket without a name
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   721
      // in which case, behavior is unspecified
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   722
      // Should this return an InetSocketAddress or an Inet6SocketAddress?
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   723
      address = InetSocketAddress (Ipv4Address::GetZero (), 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   724
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   725
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   726
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   727
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   728
/* Inherit from Socket class: Bind this socket to the specified NetDevice */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   729
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   730
TcpSocketBase::BindToNetDevice (Ptr<NetDevice> netdevice)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   731
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   732
  NS_LOG_FUNCTION (netdevice);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   733
  Socket::BindToNetDevice (netdevice); // Includes sanity check
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   734
  if (m_endPoint == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   735
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   736
      if (Bind () == -1)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   737
        {
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   738
          NS_ASSERT (m_endPoint == 0);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   739
          return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   740
        }
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   741
      NS_ASSERT (m_endPoint != 0);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   742
    }
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   743
  m_endPoint->BindToNetDevice (netdevice);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   744
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   745
  if (m_endPoint6 == 0)
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   746
    {
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   747
      if (Bind6 () == -1)
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   748
        {
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   749
          NS_ASSERT (m_endPoint6 == 0);
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   750
          return;
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   751
        }
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   752
      NS_ASSERT (m_endPoint6 != 0);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   753
    }
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   754
  m_endPoint6->BindToNetDevice (netdevice);
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   755
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   756
  return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   757
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   758
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   759
/* Clean up after Bind. Set up callback functions in the end-point. */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   760
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   761
TcpSocketBase::SetupCallback (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   762
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   763
  NS_LOG_FUNCTION (this);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   764
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   765
  if (m_endPoint == 0 && m_endPoint6 == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   766
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   767
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   768
    }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   769
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   770
    {
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   771
      m_endPoint->SetRxCallback (MakeCallback (&TcpSocketBase::ForwardUp, Ptr<TcpSocketBase> (this)));
9095
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   772
      m_endPoint->SetIcmpCallback (MakeCallback (&TcpSocketBase::ForwardIcmp, Ptr<TcpSocketBase> (this)));
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   773
      m_endPoint->SetDestroyCallback (MakeCallback (&TcpSocketBase::Destroy, Ptr<TcpSocketBase> (this)));
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   774
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   775
  if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   776
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   777
      m_endPoint6->SetRxCallback (MakeCallback (&TcpSocketBase::ForwardUp6, Ptr<TcpSocketBase> (this)));
9095
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   778
      m_endPoint6->SetIcmpCallback (MakeCallback (&TcpSocketBase::ForwardIcmp6, Ptr<TcpSocketBase> (this)));
7747
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
   779
      m_endPoint6->SetDestroyCallback (MakeCallback (&TcpSocketBase::Destroy6, Ptr<TcpSocketBase> (this)));
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   780
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   781
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   782
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   783
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   784
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   785
/* Perform the real connection tasks: Send SYN if allowed, RST if invalid */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   786
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   787
TcpSocketBase::DoConnect (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   788
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   789
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   790
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   791
  // A new connection is allowed only if this socket does not have a connection
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   792
  if (m_state == CLOSED || m_state == LISTEN || m_state == SYN_SENT || m_state == LAST_ACK || m_state == CLOSE_WAIT)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   793
    { // send a SYN packet and change state into SYN_SENT
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   794
      SendEmptyPacket (TcpHeader::SYN);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   795
      NS_LOG_INFO (TcpStateName[m_state] << " -> SYN_SENT");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   796
      m_state = SYN_SENT;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   797
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   798
  else if (m_state != TIME_WAIT)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   799
    { // In states SYN_RCVD, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, and CLOSING, an connection
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   800
      // exists. We send RST, tear down everything, and close this socket.
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   801
      SendRST ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   802
      CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   803
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   804
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   805
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   806
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   807
/* Do the action to close the socket. Usually send a packet with appropriate
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   808
    flags depended on the current m_state. */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   809
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   810
TcpSocketBase::DoClose (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   811
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   812
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   813
  switch (m_state)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   814
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   815
    case SYN_RCVD:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   816
    case ESTABLISHED:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   817
      // send FIN to close the peer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   818
      SendEmptyPacket (TcpHeader::FIN);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   819
      NS_LOG_INFO ("ESTABLISHED -> FIN_WAIT_1");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   820
      m_state = FIN_WAIT_1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   821
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   822
    case CLOSE_WAIT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   823
      // send FIN+ACK to close the peer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   824
      SendEmptyPacket (TcpHeader::FIN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   825
      NS_LOG_INFO ("CLOSE_WAIT -> LAST_ACK");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   826
      m_state = LAST_ACK;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   827
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   828
    case SYN_SENT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   829
    case CLOSING:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   830
      // Send RST if application closes in SYN_SENT and CLOSING
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   831
      SendRST ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   832
      CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   833
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   834
    case LISTEN:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   835
    case LAST_ACK:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   836
      // In these three states, move to CLOSED and tear down the end point
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   837
      CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   838
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   839
    case CLOSED:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   840
    case FIN_WAIT_1:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   841
    case FIN_WAIT_2:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   842
    case TIME_WAIT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   843
    default: /* mute compiler */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   844
      // Do nothing in these four states
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   845
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   846
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   847
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   848
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   849
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   850
/* Peacefully close the socket by notifying the upper layer and deallocate end point */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   851
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   852
TcpSocketBase::CloseAndNotify (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   853
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   854
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   855
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   856
  if (!m_closeNotified)
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   857
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   858
      NotifyNormalClose ();
11044
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
   859
      m_closeNotified = true;
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   860
    }
10694
4af272d94cfd Bug 1791
Brian Swenson <bswenson3@gatech.edu>
parents: 10652
diff changeset
   861
11044
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
   862
  NS_LOG_INFO (TcpStateName[m_state] << " -> CLOSED");
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
   863
  m_state = CLOSED;
11040
cd2eda848730 bug 1791: TCP Endpoint never deallocates when closing
Pedro Silva <pmms@inesctec.pt>
parents: 10978
diff changeset
   864
  DeallocateEndPoint ();  
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   865
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   866
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   867
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   868
/* Tell if a sequence number range is out side the range that my rx buffer can
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   869
    accpet */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   870
bool
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   871
TcpSocketBase::OutOfRange (SequenceNumber32 head, SequenceNumber32 tail) const
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   872
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   873
  if (m_state == LISTEN || m_state == SYN_SENT || m_state == SYN_RCVD)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   874
    { // Rx buffer in these states are not initialized.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   875
      return false;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   876
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   877
  if (m_state == LAST_ACK || m_state == CLOSING || m_state == CLOSE_WAIT)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   878
    { // In LAST_ACK and CLOSING states, it only wait for an ACK and the
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   879
      // sequence number must equals to m_rxBuffer->NextRxSequence ()
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   880
      return (m_rxBuffer->NextRxSequence () != head);
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   881
    }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   882
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   883
  // In all other cases, check if the sequence number is in range
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   884
  return (tail < m_rxBuffer->NextRxSequence () || m_rxBuffer->MaxRxSequence () <= head);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   885
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   886
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   887
/* Function called by the L3 protocol when it received a packet to pass on to
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   888
    the TCP. This function is registered as the "RxCallback" function in
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   889
    SetupCallback(), which invoked by Bind(), and CompleteFork() */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   890
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   891
TcpSocketBase::ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   892
                          Ptr<Ipv4Interface> incomingInterface)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   893
{
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   894
  DoForwardUp (packet, header, port, incomingInterface);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   895
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   896
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   897
void
10528
c1e835b43726 Bug 1796 - Ipv6PacketInfoTag is not filled by UdpSocketImpl::ForwardUp6.
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10410
diff changeset
   898
TcpSocketBase::ForwardUp6 (Ptr<Packet> packet, Ipv6Header header, uint16_t port, Ptr<Ipv6Interface> incomingInterface)
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   899
{
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
   900
  DoForwardUp (packet, header, port);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   901
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   902
9095
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   903
void
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   904
TcpSocketBase::ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   905
                            uint8_t icmpType, uint8_t icmpCode,
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   906
                            uint32_t icmpInfo)
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   907
{
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   908
  NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   909
                   (uint32_t)icmpCode << icmpInfo);
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   910
  if (!m_icmpCallback.IsNull ())
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   911
    {
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   912
      m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   913
    }
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   914
}
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   915
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   916
void
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   917
TcpSocketBase::ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl,
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   918
                            uint8_t icmpType, uint8_t icmpCode,
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   919
                            uint32_t icmpInfo)
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   920
{
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   921
  NS_LOG_FUNCTION (this << icmpSource << (uint32_t)icmpTtl << (uint32_t)icmpType <<
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   922
                   (uint32_t)icmpCode << icmpInfo);
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   923
  if (!m_icmpCallback6.IsNull ())
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   924
    {
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   925
      m_icmpCallback6 (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   926
    }
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   927
}
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   928
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   929
/* The real function to handle the incoming packet from lower layers. This is
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   930
    wrapped by ForwardUp() so that this function can be overloaded by daughter
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   931
    classes. */
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   932
void
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   933
TcpSocketBase::DoForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port,
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   934
                            Ptr<Ipv4Interface> incomingInterface)
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   935
{
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   936
  NS_LOG_LOGIC ("Socket " << this << " forward up " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   937
                m_endPoint->GetPeerAddress () <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   938
                ":" << m_endPoint->GetPeerPort () <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   939
                " to " << m_endPoint->GetLocalAddress () <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   940
                ":" << m_endPoint->GetLocalPort ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   941
  Address fromAddress = InetSocketAddress (header.GetSource (), port);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   942
  Address toAddress = InetSocketAddress (header.GetDestination (), m_endPoint->GetLocalPort ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   943
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   944
  // Peel off TCP header and do validity checking
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   945
  TcpHeader tcpHeader;
10943
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
   946
  uint32_t bytesRemoved = packet->RemoveHeader (tcpHeader);
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
   947
  if (bytesRemoved == 0 || bytesRemoved > 60)
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
   948
    {
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
   949
      NS_LOG_ERROR ("Bytes removed: " << bytesRemoved << " invalid");
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
   950
      return; // Discard invalid packet
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
   951
    }
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
   952
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
   953
  ReadOptions (tcpHeader);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
   954
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   955
  if (tcpHeader.GetFlags () & TcpHeader::ACK)
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   956
    {
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   957
      EstimateRtt (tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   958
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   959
7622
f2e5d5201044 TcpSocketBase improved out of range checking
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7619
diff changeset
   960
  // Discard fully out of range data packets
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   961
  if (packet->GetSize ()
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   962
      && OutOfRange (tcpHeader.GetSequenceNumber (), tcpHeader.GetSequenceNumber () + packet->GetSize ()))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   963
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   964
      NS_LOG_LOGIC ("At state " << TcpStateName[m_state] <<
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   965
                    " received packet of seq [" << tcpHeader.GetSequenceNumber () <<
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   966
                    ":" << tcpHeader.GetSequenceNumber () + packet->GetSize () <<
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   967
                    ") out of range [" << m_rxBuffer->NextRxSequence () << ":" <<
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   968
                    m_rxBuffer->MaxRxSequence () << ")");
7610
0c91f9d21f89 Send ACK to some out-of-order packets (fixes bug 1112 and part of 1256)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7608
diff changeset
   969
      // Acknowledgement should be sent for all unacceptable packets (RFC793, p.69)
0c91f9d21f89 Send ACK to some out-of-order packets (fixes bug 1112 and part of 1256)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7608
diff changeset
   970
      if (m_state == ESTABLISHED && !(tcpHeader.GetFlags () & TcpHeader::RST))
0c91f9d21f89 Send ACK to some out-of-order packets (fixes bug 1112 and part of 1256)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7608
diff changeset
   971
        {
0c91f9d21f89 Send ACK to some out-of-order packets (fixes bug 1112 and part of 1256)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7608
diff changeset
   972
          SendEmptyPacket (TcpHeader::ACK);
0c91f9d21f89 Send ACK to some out-of-order packets (fixes bug 1112 and part of 1256)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7608
diff changeset
   973
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   974
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   975
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   976
11362
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   977
  // Update Rx window size, i.e. the flow control window
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   978
  if (m_rWnd.Get () == 0 && tcpHeader.GetWindowSize () != 0 && m_persistEvent.IsRunning ())
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   979
    { // persist probes end
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   980
      NS_LOG_LOGIC (this << " Leaving zerowindow persist state");
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   981
      m_persistEvent.Cancel ();
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   982
    }
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   983
  if (tcpHeader.GetFlags () & TcpHeader::ACK)
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   984
    {
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   985
      UpdateWindowSize (tcpHeader);
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   986
    }
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
   987
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   988
  // TCP state machine code in different process functions
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   989
  // C.f.: tcp_rcv_state_process() in tcp_input.c in Linux kernel
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   990
  switch (m_state)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   991
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   992
    case ESTABLISHED:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   993
      ProcessEstablished (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   994
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   995
    case LISTEN:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   996
      ProcessListen (packet, tcpHeader, fromAddress, toAddress);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   997
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   998
    case TIME_WAIT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   999
      // Do nothing
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1000
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1001
    case CLOSED:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1002
      // Send RST if the incoming packet is not a RST
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1003
      if ((tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG)) != TcpHeader::RST)
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1004
        { // Since m_endPoint is not configured yet, we cannot use SendRST here
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1005
          TcpHeader h;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1006
          h.SetFlags (TcpHeader::RST);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1007
          h.SetSequenceNumber (m_nextTxSequence);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1008
          h.SetAckNumber (m_rxBuffer->NextRxSequence ());
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1009
          h.SetSourcePort (tcpHeader.GetDestinationPort ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1010
          h.SetDestinationPort (tcpHeader.GetSourcePort ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1011
          h.SetWindowSize (AdvertisedWindowSize ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1012
          AddOptions (h);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1013
          m_tcp->SendPacket (Create<Packet> (), h, header.GetDestination (), header.GetSource (), m_boundnetdevice);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1014
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1015
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1016
    case SYN_SENT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1017
      ProcessSynSent (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1018
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1019
    case SYN_RCVD:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1020
      ProcessSynRcvd (packet, tcpHeader, fromAddress, toAddress);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1021
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1022
    case FIN_WAIT_1:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1023
    case FIN_WAIT_2:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1024
    case CLOSE_WAIT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1025
      ProcessWait (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1026
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1027
    case CLOSING:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1028
      ProcessClosing (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1029
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1030
    case LAST_ACK:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1031
      ProcessLastAck (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1032
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1033
    default: // mute compiler
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1034
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1035
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1036
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1037
10943
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
  1038
// XXX this is duplicate code with the other DoForwardUp()
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1039
void
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1040
TcpSocketBase::DoForwardUp (Ptr<Packet> packet, Ipv6Header header, uint16_t port)
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1041
{
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1042
  NS_LOG_LOGIC ("Socket " << this << " forward up " <<
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1043
                m_endPoint6->GetPeerAddress () <<
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1044
                ":" << m_endPoint6->GetPeerPort () <<
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1045
                " to " << m_endPoint6->GetLocalAddress () <<
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1046
                ":" << m_endPoint6->GetLocalPort ());
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1047
  Address fromAddress = Inet6SocketAddress (header.GetSourceAddress (), port);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1048
  Address toAddress = Inet6SocketAddress (header.GetDestinationAddress (), m_endPoint6->GetLocalPort ());
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1049
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1050
  // Peel off TCP header and do validity checking
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1051
  TcpHeader tcpHeader;
10943
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
  1052
  uint32_t bytesRemoved = packet->RemoveHeader (tcpHeader);
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
  1053
  if (bytesRemoved == 0 || bytesRemoved > 60)
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
  1054
    {
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
  1055
      NS_LOG_ERROR ("Bytes removed: " << bytesRemoved << " invalid");
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
  1056
      return; // Discard invalid packet
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
  1057
    }
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  1058
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  1059
  ReadOptions (tcpHeader);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  1060
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1061
  if (tcpHeader.GetFlags () & TcpHeader::ACK)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1062
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1063
      EstimateRtt (tcpHeader);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1064
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1065
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1066
  // Discard fully out of range packets
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1067
  if (packet->GetSize ()
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1068
      && OutOfRange (tcpHeader.GetSequenceNumber (), tcpHeader.GetSequenceNumber () + packet->GetSize ()))
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1069
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1070
      NS_LOG_LOGIC ("At state " << TcpStateName[m_state] <<
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1071
                    " received packet of seq [" << tcpHeader.GetSequenceNumber () <<
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1072
                    ":" << tcpHeader.GetSequenceNumber () + packet->GetSize () <<
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1073
                    ") out of range [" << m_rxBuffer->NextRxSequence () << ":" <<
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1074
                    m_rxBuffer->MaxRxSequence () << ")");
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1075
      // Acknowledgement should be sent for all unacceptable packets (RFC793, p.69)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1076
      if (m_state == ESTABLISHED && !(tcpHeader.GetFlags () & TcpHeader::RST))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1077
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1078
          SendEmptyPacket (TcpHeader::ACK);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1079
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1080
      return;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1081
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1082
11362
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1083
  // Update Rx window size, i.e. the flow control window
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1084
  if (m_rWnd.Get () == 0 && tcpHeader.GetWindowSize () != 0 && m_persistEvent.IsRunning ())
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1085
    { // persist probes end
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1086
      NS_LOG_LOGIC (this << " Leaving zerowindow persist state");
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1087
      m_persistEvent.Cancel ();
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1088
    }
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1089
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1090
  if (tcpHeader.GetFlags () & TcpHeader::ACK)
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1091
    {
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1092
      UpdateWindowSize (tcpHeader);
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1093
    }
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  1094
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1095
  // TCP state machine code in different process functions
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1096
  // C.f.: tcp_rcv_state_process() in tcp_input.c in Linux kernel
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1097
  switch (m_state)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1098
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1099
    case ESTABLISHED:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1100
      ProcessEstablished (packet, tcpHeader);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1101
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1102
    case LISTEN:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1103
      ProcessListen (packet, tcpHeader, fromAddress, toAddress);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1104
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1105
    case TIME_WAIT:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1106
      // Do nothing
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1107
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1108
    case CLOSED:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1109
      // Send RST if the incoming packet is not a RST
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1110
      if ((tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG)) != TcpHeader::RST)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1111
        { // Since m_endPoint is not configured yet, we cannot use SendRST here
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1112
          TcpHeader h;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1113
          h.SetFlags (TcpHeader::RST);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1114
          h.SetSequenceNumber (m_nextTxSequence);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1115
          h.SetAckNumber (m_rxBuffer->NextRxSequence ());
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1116
          h.SetSourcePort (tcpHeader.GetDestinationPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1117
          h.SetDestinationPort (tcpHeader.GetSourcePort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1118
          h.SetWindowSize (AdvertisedWindowSize ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1119
          AddOptions (h);
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1120
          m_tcp->SendPacket (Create<Packet> (), h, header.GetDestinationAddress (), header.GetSourceAddress (), m_boundnetdevice);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1121
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1122
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1123
    case SYN_SENT:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1124
      ProcessSynSent (packet, tcpHeader);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1125
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1126
    case SYN_RCVD:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1127
      ProcessSynRcvd (packet, tcpHeader, fromAddress, toAddress);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1128
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1129
    case FIN_WAIT_1:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1130
    case FIN_WAIT_2:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1131
    case CLOSE_WAIT:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1132
      ProcessWait (packet, tcpHeader);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1133
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1134
    case CLOSING:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1135
      ProcessClosing (packet, tcpHeader);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1136
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1137
    case LAST_ACK:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1138
      ProcessLastAck (packet, tcpHeader);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1139
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1140
    default: // mute compiler
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1141
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1142
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1143
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1144
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1145
/* Received a packet upon ESTABLISHED state. This function is mimicking the
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1146
    role of tcp_rcv_established() in tcp_input.c in Linux kernel. */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1147
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1148
TcpSocketBase::ProcessEstablished (Ptr<Packet> packet, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1149
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1150
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1151
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1152
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1153
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1154
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1155
  // Different flags are different events
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1156
  if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1157
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1158
      ReceivedAck (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1159
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1160
  else if (tcpflags == TcpHeader::SYN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1161
    { // Received SYN, old NS-3 behaviour is to set state to SYN_RCVD and
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1162
      // respond with a SYN+ACK. But it is not a legal state transition as of
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1163
      // RFC793. Thus this is ignored.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1164
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1165
  else if (tcpflags == (TcpHeader::SYN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1166
    { // No action for received SYN+ACK, it is probably a duplicated packet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1167
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1168
  else if (tcpflags == TcpHeader::FIN || tcpflags == (TcpHeader::FIN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1169
    { // Received FIN or FIN+ACK, bring down this socket nicely
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1170
      PeerClose (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1171
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1172
  else if (tcpflags == 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1173
    { // No flags means there is only data
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1174
      ReceivedData (packet, tcpHeader);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1175
      if (m_rxBuffer->Finished ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1176
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1177
          PeerClose (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1178
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1179
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1180
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1181
    { // Received RST or the TCP flags is invalid, in either case, terminate this socket
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1182
      if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1183
        { // this must be an invalid flag, send reset
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1184
          NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1185
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1186
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1187
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1188
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1189
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1190
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1191
/* Process the newly received ACK */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1192
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1193
TcpSocketBase::ReceivedAck (Ptr<Packet> packet, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1194
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1195
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1196
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1197
  // Received ACK. Compare the ACK number against highest unacked seqno
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1198
  if (0 == (tcpHeader.GetFlags () & TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1199
    { // Ignore if no ACK flag
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1200
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1201
  else if (tcpHeader.GetAckNumber () < m_txBuffer->HeadSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1202
    { // Case 1: Old ACK, ignored.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1203
      NS_LOG_LOGIC ("Ignored ack of " << tcpHeader.GetAckNumber ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1204
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1205
  else if (tcpHeader.GetAckNumber () == m_txBuffer->HeadSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1206
    { // Case 2: Potentially a duplicated ACK
9078
11ac313c0610 bug 1506 dup ack piggyback fix
Brian Swenson <bswenson3@gatech.edu>
parents: 9020
diff changeset
  1207
      if (tcpHeader.GetAckNumber () < m_nextTxSequence && packet->GetSize() == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1208
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1209
          NS_LOG_LOGIC ("Dupack of " << tcpHeader.GetAckNumber ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1210
          DupAck (tcpHeader, ++m_dupAckCount);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1211
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1212
      // otherwise, the ACK is precisely equal to the nextTxSequence
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1213
      NS_ASSERT (tcpHeader.GetAckNumber () <= m_nextTxSequence);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1214
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1215
  else if (tcpHeader.GetAckNumber () > m_txBuffer->HeadSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1216
    { // Case 3: New ACK, reset m_dupAckCount and update m_txBuffer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1217
      NS_LOG_LOGIC ("New ack of " << tcpHeader.GetAckNumber ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1218
      NewAck (tcpHeader.GetAckNumber ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1219
      m_dupAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1220
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1221
  // If there is any data piggybacked, store it into m_rxBuffer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1222
  if (packet->GetSize () > 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1223
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1224
      ReceivedData (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1225
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1226
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1227
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1228
/* Received a packet upon LISTEN state. */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1229
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1230
TcpSocketBase::ProcessListen (Ptr<Packet> packet, const TcpHeader& tcpHeader,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1231
                              const Address& fromAddress, const Address& toAddress)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1232
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1233
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1234
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1235
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1236
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1237
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1238
  // Fork a socket if received a SYN. Do nothing otherwise.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1239
  // C.f.: the LISTEN part in tcp_v4_do_rcv() in tcp_ipv4.c in Linux kernel
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1240
  if (tcpflags != TcpHeader::SYN)
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1241
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1242
      return;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1243
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1244
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1245
  // Call socket's notify function to let the server app know we got a SYN
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1246
  // If the server app refuses the connection, do nothing
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1247
  if (!NotifyConnectionRequest (fromAddress))
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1248
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1249
      return;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1250
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1251
  // Clone the socket, simulate fork
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1252
  Ptr<TcpSocketBase> newSock = Fork ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1253
  NS_LOG_LOGIC ("Cloned a TcpSocketBase " << newSock);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1254
  Simulator::ScheduleNow (&TcpSocketBase::CompleteFork, newSock,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1255
                          packet, tcpHeader, fromAddress, toAddress);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1256
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1257
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1258
/* Received a packet upon SYN_SENT */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1259
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1260
TcpSocketBase::ProcessSynSent (Ptr<Packet> packet, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1261
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1262
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1263
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1264
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1265
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1266
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1267
  if (tcpflags == 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1268
    { // Bare data, accept it and move to ESTABLISHED state. This is not a normal behaviour. Remove this?
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1269
      NS_LOG_INFO ("SYN_SENT -> ESTABLISHED");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1270
      m_state = ESTABLISHED;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1271
      m_connected = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1272
      m_retxEvent.Cancel ();
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1273
      m_delAckCount = m_delAckMaxCount;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1274
      ReceivedData (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1275
      Simulator::ScheduleNow (&TcpSocketBase::ConnectionSucceeded, this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1276
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1277
  else if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1278
    { // Ignore ACK in SYN_SENT
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1279
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1280
  else if (tcpflags == TcpHeader::SYN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1281
    { // Received SYN, move to SYN_RCVD state and respond with SYN+ACK
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1282
      NS_LOG_INFO ("SYN_SENT -> SYN_RCVD");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1283
      m_state = SYN_RCVD;
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1284
      m_cnCount = m_cnRetries;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1285
      m_rxBuffer->SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1286
      SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1287
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1288
  else if (tcpflags == (TcpHeader::SYN | TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1289
           && m_nextTxSequence + SequenceNumber32 (1) == tcpHeader.GetAckNumber ())
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1290
    { // Handshake completed
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1291
      NS_LOG_INFO ("SYN_SENT -> ESTABLISHED");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1292
      m_state = ESTABLISHED;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1293
      m_connected = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1294
      m_retxEvent.Cancel ();
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1295
      m_rxBuffer->SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1296
      m_highTxMark = ++m_nextTxSequence;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1297
      m_txBuffer->SetHeadSequence (m_nextTxSequence);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1298
      SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1299
      SendPendingData (m_connected);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1300
      Simulator::ScheduleNow (&TcpSocketBase::ConnectionSucceeded, this);
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1301
      // Always respond to first data packet to speed up the connection.
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1302
      // Remove to get the behaviour of old NS-3 code.
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1303
      m_delAckCount = m_delAckMaxCount;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1304
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1305
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1306
    { // Other in-sequence input
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1307
      if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1308
        { // When (1) rx of FIN+ACK; (2) rx of FIN; (3) rx of bad flags
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1309
          NS_LOG_LOGIC ("Illegal flag " << std::hex << static_cast<uint32_t> (tcpflags) << std::dec << " received. Reset packet is sent.");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1310
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1311
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1312
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1313
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1314
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1315
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1316
/* Received a packet upon SYN_RCVD */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1317
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1318
TcpSocketBase::ProcessSynRcvd (Ptr<Packet> packet, const TcpHeader& tcpHeader,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1319
                               const Address& fromAddress, const Address& toAddress)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1320
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1321
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1322
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1323
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1324
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1325
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1326
  if (tcpflags == 0
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1327
      || (tcpflags == TcpHeader::ACK
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1328
          && m_nextTxSequence + SequenceNumber32 (1) == tcpHeader.GetAckNumber ()))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1329
    { // If it is bare data, accept it and move to ESTABLISHED state. This is
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1330
      // possibly due to ACK lost in 3WHS. If in-sequence ACK is received, the
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1331
      // handshake is completed nicely.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1332
      NS_LOG_INFO ("SYN_RCVD -> ESTABLISHED");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1333
      m_state = ESTABLISHED;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1334
      m_connected = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1335
      m_retxEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1336
      m_highTxMark = ++m_nextTxSequence;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1337
      m_txBuffer->SetHeadSequence (m_nextTxSequence);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1338
      if (m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1339
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1340
          m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1341
                               InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1342
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1343
      else if (m_endPoint6)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1344
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1345
          m_endPoint6->SetPeer (Inet6SocketAddress::ConvertFrom (fromAddress).GetIpv6 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1346
                                Inet6SocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1347
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1348
      // Always respond to first data packet to speed up the connection.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1349
      // Remove to get the behaviour of old NS-3 code.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1350
      m_delAckCount = m_delAckMaxCount;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1351
      ReceivedAck (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1352
      NotifyNewConnectionCreated (this, fromAddress);
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1353
      // As this connection is established, the socket is available to send data now
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1354
      if (GetTxAvailable () > 0)
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1355
        {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1356
          NotifySend (GetTxAvailable ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1357
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1358
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1359
  else if (tcpflags == TcpHeader::SYN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1360
    { // Probably the peer lost my SYN+ACK
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1361
      m_rxBuffer->SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1362
      SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1363
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1364
  else if (tcpflags == (TcpHeader::FIN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1365
    {
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1366
      if (tcpHeader.GetSequenceNumber () == m_rxBuffer->NextRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1367
        { // In-sequence FIN before connection complete. Set up connection and close.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1368
          m_connected = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1369
          m_retxEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1370
          m_highTxMark = ++m_nextTxSequence;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1371
          m_txBuffer->SetHeadSequence (m_nextTxSequence);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1372
          if (m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1373
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1374
              m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1375
                                   InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1376
            }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1377
          else if (m_endPoint6)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1378
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1379
              m_endPoint6->SetPeer (Inet6SocketAddress::ConvertFrom (fromAddress).GetIpv6 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1380
                                    Inet6SocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1381
            }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1382
          PeerClose (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1383
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1384
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1385
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1386
    { // Other in-sequence input
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1387
      if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1388
        { // When (1) rx of SYN+ACK; (2) rx of FIN; (3) rx of bad flags
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1389
          NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1390
          if (m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1391
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1392
              m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1393
                                   InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1394
            }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1395
          else if (m_endPoint6)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1396
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1397
              m_endPoint6->SetPeer (Inet6SocketAddress::ConvertFrom (fromAddress).GetIpv6 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1398
                                    Inet6SocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1399
            }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1400
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1401
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1402
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1403
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1404
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1405
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1406
/* Received a packet upon CLOSE_WAIT, FIN_WAIT_1, or FIN_WAIT_2 states */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1407
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1408
TcpSocketBase::ProcessWait (Ptr<Packet> packet, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1409
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1410
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1411
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1412
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1413
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1414
9020
200c9dd61e1a bug 1256: Unnecessary SND.NXT advance, missing ACK for Out of Order segments
Tom Henderson <tomh@tomh.org>
parents: 7790
diff changeset
  1415
  if (packet->GetSize () > 0 && tcpflags != TcpHeader::ACK)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1416
    { // Bare data, accept it
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1417
      ReceivedData (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1418
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1419
  else if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1420
    { // Process the ACK, and if in FIN_WAIT_1, conditionally move to FIN_WAIT_2
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1421
      ReceivedAck (packet, tcpHeader);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1422
      if (m_state == FIN_WAIT_1 && m_txBuffer->Size () == 0
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1423
          && tcpHeader.GetAckNumber () == m_highTxMark + SequenceNumber32 (1))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1424
        { // This ACK corresponds to the FIN sent
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1425
          NS_LOG_INFO ("FIN_WAIT_1 -> FIN_WAIT_2");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1426
          m_state = FIN_WAIT_2;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1427
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1428
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1429
  else if (tcpflags == TcpHeader::FIN || tcpflags == (TcpHeader::FIN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1430
    { // Got FIN, respond with ACK and move to next state
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1431
      if (tcpflags & TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1432
        { // Process the ACK first
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1433
          ReceivedAck (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1434
        }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1435
      m_rxBuffer->SetFinSequence (tcpHeader.GetSequenceNumber ());
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1436
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1437
  else if (tcpflags == TcpHeader::SYN || tcpflags == (TcpHeader::SYN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1438
    { // Duplicated SYN or SYN+ACK, possibly due to spurious retransmission
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1439
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1440
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1441
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1442
    { // This is a RST or bad flags
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1443
      if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1444
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1445
          NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1446
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1447
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1448
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1449
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1450
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1451
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1452
  // Check if the close responder sent an in-sequence FIN, if so, respond ACK
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1453
  if ((m_state == FIN_WAIT_1 || m_state == FIN_WAIT_2) && m_rxBuffer->Finished ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1454
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1455
      if (m_state == FIN_WAIT_1)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1456
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1457
          NS_LOG_INFO ("FIN_WAIT_1 -> CLOSING");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1458
          m_state = CLOSING;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1459
          if (m_txBuffer->Size () == 0
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1460
              && tcpHeader.GetAckNumber () == m_highTxMark + SequenceNumber32 (1))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1461
            { // This ACK corresponds to the FIN sent
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1462
              TimeWait ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1463
            }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1464
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1465
      else if (m_state == FIN_WAIT_2)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1466
        {
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1467
          TimeWait ();
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1468
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1469
      SendEmptyPacket (TcpHeader::ACK);
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1470
      if (!m_shutdownRecv)
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1471
        {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1472
          NotifyDataRecv ();
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1473
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1474
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1475
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1476
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1477
/* Received a packet upon CLOSING */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1478
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1479
TcpSocketBase::ProcessClosing (Ptr<Packet> packet, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1480
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1481
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1482
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1483
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1484
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1485
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1486
  if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1487
    {
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1488
      if (tcpHeader.GetSequenceNumber () == m_rxBuffer->NextRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1489
        { // This ACK corresponds to the FIN sent
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1490
          TimeWait ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1491
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1492
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1493
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1494
    { // CLOSING state means simultaneous close, i.e. no one is sending data to
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1495
      // anyone. If anything other than ACK is received, respond with a reset.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1496
      if (tcpflags == TcpHeader::FIN || tcpflags == (TcpHeader::FIN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1497
        { // FIN from the peer as well. We can close immediately.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1498
          SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1499
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1500
      else if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1501
        { // Receive of SYN or SYN+ACK or bad flags or pure data
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1502
          NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1503
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1504
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1505
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1506
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1507
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1508
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1509
/* Received a packet upon LAST_ACK */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1510
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1511
TcpSocketBase::ProcessLastAck (Ptr<Packet> packet, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1512
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1513
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1514
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1515
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1516
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1517
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1518
  if (tcpflags == 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1519
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1520
      ReceivedData (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1521
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1522
  else if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1523
    {
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1524
      if (tcpHeader.GetSequenceNumber () == m_rxBuffer->NextRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1525
        { // This ACK corresponds to the FIN sent. This socket closed peacefully.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1526
          CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1527
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1528
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1529
  else if (tcpflags == TcpHeader::FIN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1530
    { // Received FIN again, the peer probably lost the FIN+ACK
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1531
      SendEmptyPacket (TcpHeader::FIN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1532
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1533
  else if (tcpflags == (TcpHeader::FIN | TcpHeader::ACK) || tcpflags == TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1534
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1535
      CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1536
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1537
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1538
    { // Received a SYN or SYN+ACK or bad flags
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1539
      NS_LOG_LOGIC ("Illegal flag " << tcpflags << " received. Reset packet is sent.");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1540
      SendRST ();
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1541
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1542
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1543
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1544
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1545
/* Peer sent me a FIN. Remember its sequence in rx buffer. */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1546
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1547
TcpSocketBase::PeerClose (Ptr<Packet> p, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1548
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1549
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1550
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1551
  // Ignore all out of range packets
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1552
  if (tcpHeader.GetSequenceNumber () < m_rxBuffer->NextRxSequence ()
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1553
      || tcpHeader.GetSequenceNumber () > m_rxBuffer->MaxRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1554
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1555
      return;
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1556
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1557
  // For any case, remember the FIN position in rx buffer first
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1558
  m_rxBuffer->SetFinSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (p->GetSize ()));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1559
  NS_LOG_LOGIC ("Accepted FIN at seq " << tcpHeader.GetSequenceNumber () + SequenceNumber32 (p->GetSize ()));
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1560
  // If there is any piggybacked data, process it
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1561
  if (p->GetSize ())
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1562
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1563
      ReceivedData (p, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1564
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1565
  // Return if FIN is out of sequence, otherwise move to CLOSE_WAIT state by DoPeerClose
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1566
  if (!m_rxBuffer->Finished ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1567
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1568
      return;
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1569
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1570
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1571
  // Simultaneous close: Application invoked Close() when we are processing this FIN packet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1572
  if (m_state == FIN_WAIT_1)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1573
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1574
      NS_LOG_INFO ("FIN_WAIT_1 -> CLOSING");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1575
      m_state = CLOSING;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1576
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1577
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1578
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1579
  DoPeerClose (); // Change state, respond with ACK
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1580
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1581
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1582
/* Received a in-sequence FIN. Close down this socket. */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1583
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1584
TcpSocketBase::DoPeerClose (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1585
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1586
  NS_ASSERT (m_state == ESTABLISHED || m_state == SYN_RCVD);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1587
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1588
  // Move the state to CLOSE_WAIT
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1589
  NS_LOG_INFO (TcpStateName[m_state] << " -> CLOSE_WAIT");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1590
  m_state = CLOSE_WAIT;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1591
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1592
  if (!m_closeNotified)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1593
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1594
      // The normal behaviour for an application is that, when the peer sent a in-sequence
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1595
      // FIN, the app should prepare to close. The app has two choices at this point: either
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1596
      // respond with ShutdownSend() call to declare that it has nothing more to send and
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1597
      // the socket can be closed immediately; or remember the peer's close request, wait
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1598
      // until all its existing data are pushed into the TCP socket, then call Close()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1599
      // explicitly.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1600
      NS_LOG_LOGIC ("TCP " << this << " calling NotifyNormalClose");
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1601
      NotifyNormalClose ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1602
      m_closeNotified = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1603
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1604
  if (m_shutdownSend)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1605
    { // The application declares that it would not sent any more, close this socket
7256
b04ba6772f8c rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents: 7252
diff changeset
  1606
      Close ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1607
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1608
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1609
    { // Need to ack, the application will close later
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1610
      SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1611
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1612
  if (m_state == LAST_ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1613
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1614
      NS_LOG_LOGIC ("TcpSocketBase " << this << " scheduling LATO1");
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1615
      Time lastRto = m_rtt->GetEstimate () + Max (m_clockGranularity, m_rtt->GetVariation ()*4);
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1616
      m_lastAckEvent = Simulator::Schedule (lastRto, &TcpSocketBase::LastAckTimeout, this);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1617
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1618
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1619
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1620
/* Kill this socket. This is a callback function configured to m_endpoint in
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1621
   SetupCallback(), invoked when the endpoint is destroyed. */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1622
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1623
TcpSocketBase::Destroy (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1624
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1625
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1626
  m_endPoint = 0;
7747
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1627
  if (m_tcp != 0)
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1628
    {
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1629
      std::vector<Ptr<TcpSocketBase> >::iterator it
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1630
        = std::find (m_tcp->m_sockets.begin (), m_tcp->m_sockets.end (), this);
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1631
      if (it != m_tcp->m_sockets.end ())
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1632
        {
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1633
          m_tcp->m_sockets.erase (it);
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1634
        }
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1635
    }
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1636
  NS_LOG_LOGIC (this << " Cancelled ReTxTimeout event which was set to expire at " <<
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1637
                (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1638
  CancelAllTimers ();
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1639
}
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1640
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1641
/* Kill this socket. This is a callback function configured to m_endpoint in
7747
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1642
   SetupCallback(), invoked when the endpoint is destroyed. */
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1643
void
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1644
TcpSocketBase::Destroy6 (void)
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1645
{
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1646
  NS_LOG_FUNCTION (this);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1647
  m_endPoint6 = 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1648
  if (m_tcp != 0)
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1649
    {
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1650
      std::vector<Ptr<TcpSocketBase> >::iterator it
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1651
        = std::find (m_tcp->m_sockets.begin (), m_tcp->m_sockets.end (), this);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1652
      if (it != m_tcp->m_sockets.end ())
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1653
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1654
          m_tcp->m_sockets.erase (it);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1655
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1656
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1657
  NS_LOG_LOGIC (this << " Cancelled ReTxTimeout event which was set to expire at " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1658
                (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1659
  CancelAllTimers ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1660
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1661
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1662
/* Send an empty packet with specified TCP flags */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1663
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1664
TcpSocketBase::SendEmptyPacket (uint8_t flags)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1665
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1666
  NS_LOG_FUNCTION (this << (uint32_t)flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1667
  Ptr<Packet> p = Create<Packet> ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1668
  TcpHeader header;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1669
  SequenceNumber32 s = m_nextTxSequence;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1670
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1671
  /*
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1672
   * Add tags for each socket option.
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1673
   * Note that currently the socket adds both IPv4 tag and IPv6 tag
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1674
   * if both options are set. Once the packet got to layer three, only
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1675
   * the corresponding tags will be read.
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1676
   */
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1677
  if (IsManualIpTos ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1678
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1679
      SocketIpTosTag ipTosTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1680
      ipTosTag.SetTos (GetIpTos ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1681
      p->AddPacketTag (ipTosTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1682
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1683
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1684
  if (IsManualIpv6Tclass ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1685
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1686
      SocketIpv6TclassTag ipTclassTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1687
      ipTclassTag.SetTclass (GetIpv6Tclass ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1688
      p->AddPacketTag (ipTclassTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1689
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1690
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1691
  if (IsManualIpTtl ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1692
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1693
      SocketIpTtlTag ipTtlTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1694
      ipTtlTag.SetTtl (GetIpTtl ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1695
      p->AddPacketTag (ipTtlTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1696
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1697
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1698
  if (IsManualIpv6HopLimit ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1699
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1700
      SocketIpv6HopLimitTag ipHopLimitTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1701
      ipHopLimitTag.SetHopLimit (GetIpv6HopLimit ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1702
      p->AddPacketTag (ipHopLimitTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1703
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1704
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1705
  if (m_endPoint == 0 && m_endPoint6 == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1706
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1707
      NS_LOG_WARN ("Failed to send empty packet due to null endpoint");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1708
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1709
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1710
  if (flags & TcpHeader::FIN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1711
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1712
      flags |= TcpHeader::ACK;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1713
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1714
  else if (m_state == FIN_WAIT_1 || m_state == LAST_ACK || m_state == CLOSING)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1715
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1716
      ++s;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1717
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1718
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1719
  header.SetFlags (flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1720
  header.SetSequenceNumber (s);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1721
  header.SetAckNumber (m_rxBuffer->NextRxSequence ());
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1722
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1723
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1724
      header.SetSourcePort (m_endPoint->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1725
      header.SetDestinationPort (m_endPoint->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1726
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1727
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1728
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1729
      header.SetSourcePort (m_endPoint6->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1730
      header.SetDestinationPort (m_endPoint6->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1731
    }
10912
4734ff3dd909 calculate send scale factor when sending the SYN-ACK instead of when reading the SYN options
Tom Henderson <tomh@tomh.org>
parents: 10911
diff changeset
  1732
  AddOptions (header);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1733
  header.SetWindowSize (AdvertisedWindowSize ());
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1734
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1735
  // RFC 6298, clause 2.4
11231
62ce11a18acd Bug 2076 - TCP MinRTO Attribute is not actually used
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11202
diff changeset
  1736
  m_rto = Max (m_rtt->GetEstimate () + Max (m_clockGranularity, m_rtt->GetVariation ()*4), m_minRto);
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1737
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1738
  bool hasSyn = flags & TcpHeader::SYN;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1739
  bool hasFin = flags & TcpHeader::FIN;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1740
  bool isAck = flags == TcpHeader::ACK;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1741
  if (hasSyn)
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1742
    {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1743
      if (m_cnCount == 0)
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1744
        { // No more connection retries, give up
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1745
          NS_LOG_LOGIC ("Connection failed.");
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1746
          m_rtt->Reset (); //According to recommendation -> RFC 6298
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1747
          CloseAndNotify ();
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1748
          return;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1749
        }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1750
      else
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1751
        { // Exponential backoff of connection time out
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1752
          int backoffCount = 0x1 << (m_cnRetries - m_cnCount);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1753
          m_rto = m_cnTimeout * backoffCount;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1754
          m_cnCount--;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1755
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1756
    }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1757
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1758
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1759
      m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1760
                         m_endPoint->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1761
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1762
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1763
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1764
      m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1765
                         m_endPoint6->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1766
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1767
  if (flags & TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1768
    { // If sending an ACK, cancel the delay ACK as well
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1769
      m_delAckEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1770
      m_delAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1771
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1772
  if (m_retxEvent.IsExpired () && (hasSyn || hasFin) && !isAck )
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1773
    { // Retransmit SYN / SYN+ACK / FIN / FIN+ACK to guard against lost
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1774
      NS_LOG_LOGIC ("Schedule retransmission timeout at time "
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1775
                    << Simulator::Now ().GetSeconds () << " to expire at time "
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1776
                    << (Simulator::Now () + m_rto.Get ()).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1777
      m_retxEvent = Simulator::Schedule (m_rto, &TcpSocketBase::SendEmptyPacket, this, flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1778
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1779
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1780
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1781
/* This function closes the endpoint completely. Called upon RST_TX action. */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1782
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1783
TcpSocketBase::SendRST (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1784
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1785
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1786
  SendEmptyPacket (TcpHeader::RST);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1787
  NotifyErrorClose ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1788
  DeallocateEndPoint ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1789
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1790
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1791
/* Deallocate the end point and cancel all the timers */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1792
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1793
TcpSocketBase::DeallocateEndPoint (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1794
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1795
  if (m_endPoint != 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1796
    {
11044
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
  1797
      CancelAllTimers ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1798
      m_endPoint->SetDestroyCallback (MakeNullCallback<void> ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1799
      m_tcp->DeAllocate (m_endPoint);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1800
      m_endPoint = 0;
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1801
      std::vector<Ptr<TcpSocketBase> >::iterator it
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1802
        = std::find (m_tcp->m_sockets.begin (), m_tcp->m_sockets.end (), this);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1803
      if (it != m_tcp->m_sockets.end ())
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1804
        {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1805
          m_tcp->m_sockets.erase (it);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1806
        }
11044
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
  1807
    }
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
  1808
  else if (m_endPoint6 != 0)
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
  1809
    {
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1810
      CancelAllTimers ();
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1811
      m_endPoint6->SetDestroyCallback (MakeNullCallback<void> ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1812
      m_tcp->DeAllocate (m_endPoint6);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1813
      m_endPoint6 = 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1814
      std::vector<Ptr<TcpSocketBase> >::iterator it
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1815
        = std::find (m_tcp->m_sockets.begin (), m_tcp->m_sockets.end (), this);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1816
      if (it != m_tcp->m_sockets.end ())
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1817
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1818
          m_tcp->m_sockets.erase (it);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1819
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1820
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1821
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1822
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1823
/* Configure the endpoint to a local address. Called by Connect() if Bind() didn't specify one. */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1824
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1825
TcpSocketBase::SetupEndpoint ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1826
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1827
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1828
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1829
  NS_ASSERT (ipv4 != 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1830
  if (ipv4->GetRoutingProtocol () == 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1831
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1832
      NS_FATAL_ERROR ("No Ipv4RoutingProtocol in the node");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1833
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1834
  // Create a dummy packet, then ask the routing function for the best output
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1835
  // interface's address
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1836
  Ipv4Header header;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1837
  header.SetDestination (m_endPoint->GetPeerAddress ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1838
  Socket::SocketErrno errno_;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1839
  Ptr<Ipv4Route> route;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1840
  Ptr<NetDevice> oif = m_boundnetdevice;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1841
  route = ipv4->GetRoutingProtocol ()->RouteOutput (Ptr<Packet> (), header, oif, errno_);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1842
  if (route == 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1843
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1844
      NS_LOG_LOGIC ("Route to " << m_endPoint->GetPeerAddress () << " does not exist");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1845
      NS_LOG_ERROR (errno_);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1846
      m_errno = errno_;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1847
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1848
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1849
  NS_LOG_LOGIC ("Route exists");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1850
  m_endPoint->SetLocalAddress (route->GetSource ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1851
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1852
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1853
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1854
int
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1855
TcpSocketBase::SetupEndpoint6 ()
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1856
{
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1857
  NS_LOG_FUNCTION (this);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1858
  Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol> ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1859
  NS_ASSERT (ipv6 != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1860
  if (ipv6->GetRoutingProtocol () == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1861
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1862
      NS_FATAL_ERROR ("No Ipv6RoutingProtocol in the node");
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1863
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1864
  // Create a dummy packet, then ask the routing function for the best output
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1865
  // interface's address
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1866
  Ipv6Header header;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1867
  header.SetDestinationAddress (m_endPoint6->GetPeerAddress ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1868
  Socket::SocketErrno errno_;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1869
  Ptr<Ipv6Route> route;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1870
  Ptr<NetDevice> oif = m_boundnetdevice;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1871
  route = ipv6->GetRoutingProtocol ()->RouteOutput (Ptr<Packet> (), header, oif, errno_);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1872
  if (route == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1873
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1874
      NS_LOG_LOGIC ("Route to " << m_endPoint6->GetPeerAddress () << " does not exist");
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1875
      NS_LOG_ERROR (errno_);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1876
      m_errno = errno_;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1877
      return -1;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1878
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1879
  NS_LOG_LOGIC ("Route exists");
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1880
  m_endPoint6->SetLocalAddress (route->GetSource ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1881
  return 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1882
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1883
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1884
/* This function is called only if a SYN received in LISTEN state. After
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1885
   TcpSocketBase cloned, allocate a new end point to handle the incoming
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1886
   connection and send a SYN+ACK to complete the handshake. */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1887
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1888
TcpSocketBase::CompleteFork (Ptr<Packet> p, const TcpHeader& h,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1889
                             const Address& fromAddress, const Address& toAddress)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1890
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1891
  // Get port and address from peer (connecting host)
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1892
  if (InetSocketAddress::IsMatchingType (toAddress))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1893
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1894
      m_endPoint = m_tcp->Allocate (InetSocketAddress::ConvertFrom (toAddress).GetIpv4 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1895
                                    InetSocketAddress::ConvertFrom (toAddress).GetPort (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1896
                                    InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1897
                                    InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1898
      m_endPoint6 = 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1899
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1900
  else if (Inet6SocketAddress::IsMatchingType (toAddress))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1901
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1902
      m_endPoint6 = m_tcp->Allocate6 (Inet6SocketAddress::ConvertFrom (toAddress).GetIpv6 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1903
                                      Inet6SocketAddress::ConvertFrom (toAddress).GetPort (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1904
                                      Inet6SocketAddress::ConvertFrom (fromAddress).GetIpv6 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1905
                                      Inet6SocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1906
      m_endPoint = 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1907
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1908
  m_tcp->m_sockets.push_back (this);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1909
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1910
  // Change the cloned socket from LISTEN state to SYN_RCVD
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1911
  NS_LOG_INFO ("LISTEN -> SYN_RCVD");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1912
  m_state = SYN_RCVD;
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1913
  m_cnCount = m_cnRetries;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1914
  SetupCallback ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1915
  // Set the sequence number and send SYN+ACK
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1916
  m_rxBuffer->SetNextRxSequence (h.GetSequenceNumber () + SequenceNumber32 (1));
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  1917
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1918
  SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1919
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1920
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1921
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1922
TcpSocketBase::ConnectionSucceeded ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1923
{ // Wrapper to protected function NotifyConnectionSucceeded() so that it can
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1924
  // be called as a scheduled event
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1925
  NotifyConnectionSucceeded ();
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1926
  // The if-block below was moved from ProcessSynSent() to here because we need
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1927
  // to invoke the NotifySend() only after NotifyConnectionSucceeded() to
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1928
  // reflect the behaviour in the real world.
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1929
  if (GetTxAvailable () > 0)
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1930
    {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1931
      NotifySend (GetTxAvailable ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1932
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1933
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1934
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1935
/* Extract at most maxSize bytes from the TxBuffer at sequence seq, add the
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1936
    TCP header, and send to TcpL4Protocol */
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1937
uint32_t
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1938
TcpSocketBase::SendDataPacket (SequenceNumber32 seq, uint32_t maxSize, bool withAck)
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1939
{
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1940
  NS_LOG_FUNCTION (this << seq << maxSize << withAck);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1941
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1942
  bool isRetransmission = false;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1943
  if ( seq == m_txBuffer->HeadSequence () )
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1944
    {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1945
      isRetransmission = true;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1946
    }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1947
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1948
  Ptr<Packet> p = m_txBuffer->CopyFromSequence (maxSize, seq);
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1949
  uint32_t sz = p->GetSize (); // Size of packet
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1950
  uint8_t flags = withAck ? TcpHeader::ACK : 0;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1951
  uint32_t remainingData = m_txBuffer->SizeFromSequence (seq + SequenceNumber32 (sz));
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1952
11202
6286a5dc3f64 bug 1734: TcpSocketBase produces spurious delayed ACKs (fix due to Lawrence Stewart)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11195
diff changeset
  1953
  if (withAck)
6286a5dc3f64 bug 1734: TcpSocketBase produces spurious delayed ACKs (fix due to Lawrence Stewart)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11195
diff changeset
  1954
    {
6286a5dc3f64 bug 1734: TcpSocketBase produces spurious delayed ACKs (fix due to Lawrence Stewart)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11195
diff changeset
  1955
      m_delAckEvent.Cancel ();
6286a5dc3f64 bug 1734: TcpSocketBase produces spurious delayed ACKs (fix due to Lawrence Stewart)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11195
diff changeset
  1956
      m_delAckCount = 0;
6286a5dc3f64 bug 1734: TcpSocketBase produces spurious delayed ACKs (fix due to Lawrence Stewart)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11195
diff changeset
  1957
    }
6286a5dc3f64 bug 1734: TcpSocketBase produces spurious delayed ACKs (fix due to Lawrence Stewart)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11195
diff changeset
  1958
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1959
  /*
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1960
   * Add tags for each socket option.
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1961
   * Note that currently the socket adds both IPv4 tag and IPv6 tag
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1962
   * if both options are set. Once the packet got to layer three, only
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1963
   * the corresponding tags will be read.
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1964
   */
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1965
  if (IsManualIpTos ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1966
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1967
      SocketIpTosTag ipTosTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1968
      ipTosTag.SetTos (GetIpTos ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1969
      p->AddPacketTag (ipTosTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1970
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1971
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1972
  if (IsManualIpv6Tclass ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1973
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1974
      SocketIpv6TclassTag ipTclassTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1975
      ipTclassTag.SetTclass (GetIpv6Tclass ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1976
      p->AddPacketTag (ipTclassTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1977
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1978
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1979
  if (IsManualIpTtl ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1980
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1981
      SocketIpTtlTag ipTtlTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1982
      ipTtlTag.SetTtl (GetIpTtl ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1983
      p->AddPacketTag (ipTtlTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1984
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1985
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1986
  if (IsManualIpv6HopLimit ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1987
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1988
      SocketIpv6HopLimitTag ipHopLimitTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1989
      ipHopLimitTag.SetHopLimit (GetIpv6HopLimit ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1990
      p->AddPacketTag (ipHopLimitTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1991
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1992
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1993
  if (m_closeOnEmpty && (remainingData == 0))
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1994
    {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1995
      flags |= TcpHeader::FIN;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1996
      if (m_state == ESTABLISHED)
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1997
        { // On active close: I am the first one to send FIN
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1998
          NS_LOG_INFO ("ESTABLISHED -> FIN_WAIT_1");
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1999
          m_state = FIN_WAIT_1;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2000
        }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2001
      else if (m_state == CLOSE_WAIT)
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2002
        { // On passive close: Peer sent me FIN already
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2003
          NS_LOG_INFO ("CLOSE_WAIT -> LAST_ACK");
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2004
          m_state = LAST_ACK;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2005
        }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2006
    }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2007
  TcpHeader header;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2008
  header.SetFlags (flags);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2009
  header.SetSequenceNumber (seq);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2010
  header.SetAckNumber (m_rxBuffer->NextRxSequence ());
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2011
  if (m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2012
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2013
      header.SetSourcePort (m_endPoint->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2014
      header.SetDestinationPort (m_endPoint->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2015
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2016
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2017
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2018
      header.SetSourcePort (m_endPoint6->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2019
      header.SetDestinationPort (m_endPoint6->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2020
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2021
  header.SetWindowSize (AdvertisedWindowSize ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2022
  AddOptions (header);
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2023
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2024
  if (m_retxEvent.IsExpired () )
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2025
    {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2026
      // RFC 6298, clause 2.5
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2027
      Time doubledRto = m_rto + m_rto;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2028
      m_rto = Min (doubledRto, Time::FromDouble (60,  Time::S));
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2029
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2030
      // Schedules retransmit
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2031
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2032
      NS_LOG_LOGIC (this << " SendDataPacket Schedule ReTxTimeout at time " <<
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2033
                    Simulator::Now ().GetSeconds () << " to expire at time " <<
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2034
                    (Simulator::Now () + m_rto.Get ()).GetSeconds () );
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2035
      m_retxEvent = Simulator::Schedule (m_rto, &TcpSocketBase::ReTxTimeout, this);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2036
    }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2037
  NS_LOG_LOGIC ("Send packet via TcpL4Protocol with flags 0x" << std::hex << static_cast<uint32_t> (flags) << std::dec);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2038
  if (m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2039
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2040
      m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2041
                         m_endPoint->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2042
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2043
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2044
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2045
      m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2046
                         m_endPoint6->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2047
    }
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2048
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2049
  // update the history of sequence numbers used to calculate the RTT
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2050
  if (isRetransmission == false)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2051
    { // This is the next expected one, just log at end
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2052
      m_history.push_back (RttHistory (seq, sz, Simulator::Now () ));
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2053
    }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2054
  else
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2055
    { // This is a retransmit, find in list and mark as re-tx
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2056
      for (RttHistory_t::iterator i = m_history.begin (); i != m_history.end (); ++i)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2057
        {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2058
          if ((seq >= i->seq) && (seq < (i->seq + SequenceNumber32 (i->count))))
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2059
            { // Found it
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2060
              i->retx = true;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2061
              i->count = ((seq + SequenceNumber32 (sz)) - i->seq); // And update count in hist
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2062
              break;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2063
            }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2064
        }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2065
    }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2066
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2067
  // Notify the application of the data being sent unless this is a retransmit
11193
f35b8f7e50f1 Bug 2053 - In tcp-socket-base.cc, NotifyDataSent incorrectly called with retransmits
Steve Zabele <zabele@comcast.net>
parents: 11190
diff changeset
  2068
  if (seq == m_highTxMark)
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2069
    {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2070
      Simulator::ScheduleNow (&TcpSocketBase::NotifyDataSent, this, sz);
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2071
    }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2072
  // Update highTxMark
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2073
  m_highTxMark = std::max (seq + sz, m_highTxMark.Get ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2074
  return sz;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2075
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2076
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  2077
/* Send as much pending data as possible according to the Tx window. Note that
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2078
 *  this function did not implement the PSH flag
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2079
 */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2080
bool
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2081
TcpSocketBase::SendPendingData (bool withAck)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2082
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2083
  NS_LOG_FUNCTION (this << withAck);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2084
  if (m_txBuffer->Size () == 0)
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2085
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2086
      return false;                           // Nothing to send
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2087
    }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2088
  if (m_endPoint == 0 && m_endPoint6 == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2089
    {
6768
805f5fc7f670 remove stale doxygen and comments pertaining to TCP
Tom Henderson <tomh@tomh.org>
parents: 6738
diff changeset
  2090
      NS_LOG_INFO ("TcpSocketBase::SendPendingData: No endpoint; m_shutdownSend=" << m_shutdownSend);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2091
      return false; // Is this the right way to handle this condition?
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2092
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2093
  uint32_t nPacketsSent = 0;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2094
  while (m_txBuffer->SizeFromSequence (m_nextTxSequence))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2095
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2096
      uint32_t w = AvailableWindow (); // Get available window size
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2097
      // Stop sending if we need to wait for a larger Tx window (prevent silly window syndrome)
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2098
      if (w < m_segmentSize && m_txBuffer->SizeFromSequence (m_nextTxSequence) > w)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2099
        {
11359
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2100
          NS_LOG_LOGIC ("Preventing Silly Window Syndrome. Wait to send.");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2101
          break; // No more
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2102
        }
7619
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2103
      // Nagle's algorithm (RFC896): Hold off sending if there is unacked data
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2104
      // in the buffer and the amount of data to send is less than one segment
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2105
      if (!m_noDelay && UnAckDataCount () > 0
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2106
          && m_txBuffer->SizeFromSequence (m_nextTxSequence) < m_segmentSize)
7619
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2107
        {
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2108
          NS_LOG_LOGIC ("Invoking Nagle's algorithm. Wait to send.");
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2109
          break;
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2110
        }
11359
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2111
      NS_LOG_LOGIC ("TcpSocketBase " << this << " SendPendingData" <<
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2112
                    " w " << w <<
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2113
                    " rxwin " << m_rWnd <<
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2114
                    " segsize " << m_segmentSize <<
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2115
                    " nextTxSeq " << m_nextTxSequence <<
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2116
                    " highestRxAck " << m_txBuffer->HeadSequence () <<
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2117
                    " pd->Size " << m_txBuffer->Size () <<
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2118
                    " pd->SFS " << m_txBuffer->SizeFromSequence (m_nextTxSequence));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2119
      uint32_t s = std::min (w, m_segmentSize);  // Send no more than window
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2120
      uint32_t sz = SendDataPacket (m_nextTxSequence, s, withAck);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2121
      nPacketsSent++;                             // Count sent this loop
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2122
      m_nextTxSequence += sz;                     // Advance next tx sequence
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2123
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2124
  NS_LOG_LOGIC ("SendPendingData sent " << nPacketsSent << " packets");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2125
  return (nPacketsSent > 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2126
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2127
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2128
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2129
TcpSocketBase::UnAckDataCount ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2130
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2131
  NS_LOG_FUNCTION (this);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2132
  return m_nextTxSequence.Get () - m_txBuffer->HeadSequence ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2133
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2134
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2135
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2136
TcpSocketBase::BytesInFlight ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2137
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2138
  NS_LOG_FUNCTION (this);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2139
  return m_highTxMark.Get () - m_txBuffer->HeadSequence ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2140
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2141
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2142
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2143
TcpSocketBase::AvailableWindow ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2144
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2145
  NS_LOG_FUNCTION_NOARGS ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2146
  uint32_t unack = UnAckDataCount (); // Number of outstanding bytes
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2147
  uint32_t win = Window (); // Number of bytes allowed to be outstanding
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2148
  NS_LOG_LOGIC ("UnAckCount=" << unack << ", Win=" << win);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2149
  return (win < unack) ? 0 : (win - unack);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2150
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2151
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2152
uint16_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2153
TcpSocketBase::AdvertisedWindowSize ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2154
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2155
  uint32_t w = m_rxBuffer->MaxBufferSize () - m_rxBuffer->Size ();
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2156
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2157
  w >>= m_sndScaleFactor;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2158
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2159
  if (w > m_maxWinSize)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2160
    {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2161
      NS_LOG_WARN ("There is a loss in the adv win size, wrt buffer size");
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2162
      w = m_maxWinSize;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2163
    }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2164
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2165
  return (uint16_t) w;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2166
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2167
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2168
// Receipt of new packet, put into Rx buffer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2169
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2170
TcpSocketBase::ReceivedData (Ptr<Packet> p, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2171
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2172
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2173
  NS_LOG_LOGIC ("seq " << tcpHeader.GetSequenceNumber () <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2174
                " ack " << tcpHeader.GetAckNumber () <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2175
                " pkt size " << p->GetSize () );
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2176
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2177
  // Put into Rx buffer
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2178
  SequenceNumber32 expectedSeq = m_rxBuffer->NextRxSequence ();
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2179
  if (!m_rxBuffer->Add (p, tcpHeader))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2180
    { // Insert failed: No data or RX buffer full
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2181
      SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2182
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2183
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2184
  // Now send a new ACK packet acknowledging all received and delivered data
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2185
  if (m_rxBuffer->Size () > m_rxBuffer->Available () || m_rxBuffer->NextRxSequence () > expectedSeq + p->GetSize ())
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2186
    { // A gap exists in the buffer, or we filled a gap: Always ACK
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2187
      SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2188
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2189
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2190
    { // In-sequence packet: ACK if delayed ack count allows
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2191
      if (++m_delAckCount >= m_delAckMaxCount)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2192
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2193
          m_delAckEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2194
          m_delAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2195
          SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2196
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2197
      else if (m_delAckEvent.IsExpired ())
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2198
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2199
          m_delAckEvent = Simulator::Schedule (m_delAckTimeout,
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
  2200
                                               &TcpSocketBase::DelAckTimeout, this);
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2201
          NS_LOG_LOGIC (this << " scheduled delayed ACK at " << (Simulator::Now () + Simulator::GetDelayLeft (m_delAckEvent)).GetSeconds ());
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2202
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2203
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2204
  // Notify app to receive if necessary
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2205
  if (expectedSeq < m_rxBuffer->NextRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2206
    { // NextRxSeq advanced, we have something to send to the app
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2207
      if (!m_shutdownRecv)
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2208
        {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2209
          NotifyDataRecv ();
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2210
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2211
      // Handle exceptions
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2212
      if (m_closeNotified)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2213
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2214
          NS_LOG_WARN ("Why TCP " << this << " got data after close notification?");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2215
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2216
      // If we received FIN before and now completed all "holes" in rx buffer,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2217
      // invoke peer close procedure
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2218
      if (m_rxBuffer->Finished () && (tcpHeader.GetFlags () & TcpHeader::FIN) == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2219
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2220
          DoPeerClose ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2221
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2222
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2223
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2224
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2225
/**
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2226
 * \brief Estimate the RTT
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2227
 *
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2228
 * Called by ForwardUp() to estimate RTT.
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2229
 *
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2230
 * \param tcpHeader TCP header for the incoming packet
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2231
 */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2232
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2233
TcpSocketBase::EstimateRtt (const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2234
{
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2235
  SequenceNumber32 ackSeq = tcpHeader.GetAckNumber();
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2236
  Time m = Time (0.0);
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2237
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2238
  // An ack has been received, calculate rtt and log this measurement
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2239
  // Note we use a linear search (O(n)) for this since for the common
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2240
  // case the ack'ed packet will be at the head of the list
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2241
  if (!m_history.empty ())
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2242
    {
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2243
      RttHistory& h = m_history.front ();
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2244
      if (!h.retx && ackSeq >= (h.seq + SequenceNumber32 (h.count)))
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2245
        { // Ok to use this sample
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2246
          if (m_timestampEnabled && tcpHeader.HasOption (TcpOption::TS))
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2247
            {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2248
              Ptr<TcpOptionTS> ts;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2249
              ts = DynamicCast<TcpOptionTS> (tcpHeader.GetOption (TcpOption::TS));
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2250
              m = TcpOptionTS::ElapsedTimeFromTsValue (ts->GetEcho ());
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2251
            }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2252
          else
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2253
            {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2254
              m = Simulator::Now () - h.time; // Elapsed time
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2255
            }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2256
        }
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2257
    }
9118
5991df10eb5e bug 1509 RTTEstimator invalid values fix
Brian Swenson <bswenson3@gatech.edu>
parents: 9095
diff changeset
  2258
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2259
  // Now delete all ack history with seq <= ack
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2260
  while(!m_history.empty ())
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2261
    {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2262
      RttHistory& h = m_history.front ();
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2263
      if ((h.seq + SequenceNumber32 (h.count)) > ackSeq) break;               // Done removing
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2264
      m_history.pop_front (); // Remove
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2265
    }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2266
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2267
  if (!m.IsZero ())
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2268
    {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2269
      m_rtt->Measurement (m);                // Log the measurement
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2270
      // RFC 6298, clause 2.4
11231
62ce11a18acd Bug 2076 - TCP MinRTO Attribute is not actually used
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11202
diff changeset
  2271
      m_rto = Max (m_rtt->GetEstimate () + Max (m_clockGranularity, m_rtt->GetVariation ()*4), m_minRto);
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2272
      m_lastRtt = m_rtt->GetEstimate ();
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2273
      NS_LOG_FUNCTION(this << m_lastRtt);
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2274
    }
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2275
}
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2276
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2277
// Called by the ReceivedAck() when new ACK received and by ProcessSynRcvd()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2278
// when the three-way handshake completed. This cancels retransmission timer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2279
// and advances Tx window
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2280
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2281
TcpSocketBase::NewAck (SequenceNumber32 const& ack)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2282
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2283
  NS_LOG_FUNCTION (this << ack);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2284
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2285
  if (m_state != SYN_RCVD)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2286
    { // Set RTO unless the ACK is received in SYN_RCVD state
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2287
      NS_LOG_LOGIC (this << " Cancelled ReTxTimeout event which was set to expire at " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2288
                    (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2289
      m_retxEvent.Cancel ();
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2290
      // On receiving a "New" ack we restart retransmission timer .. RFC 6298
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2291
      // RFC 6298, clause 2.4
11231
62ce11a18acd Bug 2076 - TCP MinRTO Attribute is not actually used
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11202
diff changeset
  2292
      m_rto = Max (m_rtt->GetEstimate () + Max (m_clockGranularity, m_rtt->GetVariation ()*4), m_minRto);
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2293
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2294
      NS_LOG_LOGIC (this << " Schedule ReTxTimeout at time " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2295
                    Simulator::Now ().GetSeconds () << " to expire at time " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2296
                    (Simulator::Now () + m_rto.Get ()).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2297
      m_retxEvent = Simulator::Schedule (m_rto, &TcpSocketBase::ReTxTimeout, this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2298
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2299
  if (m_rWnd.Get () == 0 && m_persistEvent.IsExpired ())
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2300
    { // Zero window: Enter persist state to send 1 byte to probe
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2301
      NS_LOG_LOGIC (this << "Enter zerowindow persist state");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2302
      NS_LOG_LOGIC (this << "Cancelled ReTxTimeout event which was set to expire at " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2303
                    (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2304
      m_retxEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2305
      NS_LOG_LOGIC ("Schedule persist timeout at time " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2306
                    Simulator::Now ().GetSeconds () << " to expire at time " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2307
                    (Simulator::Now () + m_persistTimeout).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2308
      m_persistEvent = Simulator::Schedule (m_persistTimeout, &TcpSocketBase::PersistTimeout, this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2309
      NS_ASSERT (m_persistTimeout == Simulator::GetDelayLeft (m_persistEvent));
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2310
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2311
  // Note the highest ACK and tell app to send more
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2312
  NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack <<
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2313
                " numberAck " << (ack - m_txBuffer->HeadSequence ())); // Number bytes ack'ed
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2314
  m_txBuffer->DiscardUpTo (ack);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2315
  if (GetTxAvailable () > 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2316
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2317
      NotifySend (GetTxAvailable ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2318
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2319
  if (ack > m_nextTxSequence)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2320
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2321
      m_nextTxSequence = ack; // If advanced
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2322
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2323
  if (m_txBuffer->Size () == 0 && m_state != FIN_WAIT_1 && m_state != CLOSING)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2324
    { // No retransmit timer if no data to retransmit
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2325
      NS_LOG_LOGIC (this << " Cancelled ReTxTimeout event which was set to expire at " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2326
                    (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2327
      m_retxEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2328
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2329
  // Try to send more data
11359
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2330
  if (!m_sendPendingDataEvent.IsRunning ())
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2331
    {
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2332
      m_sendPendingDataEvent = Simulator::Schedule ( TimeStep (1), &TcpSocketBase::SendPendingData, this, m_connected);
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2333
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2334
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2335
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2336
// Retransmit timeout
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2337
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2338
TcpSocketBase::ReTxTimeout ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2339
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2340
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2341
  NS_LOG_LOGIC (this << " ReTxTimeout Expired at time " << Simulator::Now ().GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2342
  // If erroneous timeout in closed/timed-wait state, just return
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2343
  if (m_state == CLOSED || m_state == TIME_WAIT)
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2344
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2345
      return;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2346
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2347
  // If all data are received (non-closing socket and nothing to send), just return
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2348
  if (m_state <= ESTABLISHED && m_txBuffer->HeadSequence () >= m_highTxMark)
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2349
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2350
      return;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2351
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2352
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2353
  Retransmit ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2354
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2355
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2356
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2357
TcpSocketBase::DelAckTimeout (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2358
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2359
  m_delAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2360
  SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2361
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2362
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2363
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2364
TcpSocketBase::LastAckTimeout (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2365
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2366
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2367
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2368
  m_lastAckEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2369
  if (m_state == LAST_ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2370
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2371
      CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2372
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2373
  if (!m_closeNotified)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2374
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2375
      m_closeNotified = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2376
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2377
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2378
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2379
// Send 1-byte data to probe for the window size at the receiver when
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2380
// the local knowledge tells that the receiver has zero window size
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2381
// C.f.: RFC793 p.42, RFC1112 sec.4.2.2.17
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2382
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2383
TcpSocketBase::PersistTimeout ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2384
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2385
  NS_LOG_LOGIC ("PersistTimeout expired at " << Simulator::Now ().GetSeconds ());
7045
d13fa06886ce merge with HEAD
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6834
diff changeset
  2386
  m_persistTimeout = std::min (Seconds (60), Time (2 * m_persistTimeout)); // max persist timeout = 60s
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2387
  Ptr<Packet> p = m_txBuffer->CopyFromSequence (1, m_nextTxSequence);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2388
  TcpHeader tcpHeader;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2389
  tcpHeader.SetSequenceNumber (m_nextTxSequence);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2390
  tcpHeader.SetAckNumber (m_rxBuffer->NextRxSequence ());
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2391
  tcpHeader.SetWindowSize (AdvertisedWindowSize ());
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2392
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2393
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2394
      tcpHeader.SetSourcePort (m_endPoint->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2395
      tcpHeader.SetDestinationPort (m_endPoint->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2396
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2397
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2398
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2399
      tcpHeader.SetSourcePort (m_endPoint6->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2400
      tcpHeader.SetDestinationPort (m_endPoint6->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2401
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2402
  AddOptions (tcpHeader);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2403
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2404
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2405
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2406
      m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2407
                         m_endPoint->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2408
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2409
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2410
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2411
      m_tcp->SendPacket (p, tcpHeader, m_endPoint6->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2412
                         m_endPoint6->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2413
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2414
  NS_LOG_LOGIC ("Schedule persist timeout at time "
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2415
                << Simulator::Now ().GetSeconds () << " to expire at time "
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2416
                << (Simulator::Now () + m_persistTimeout).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2417
  m_persistEvent = Simulator::Schedule (m_persistTimeout, &TcpSocketBase::PersistTimeout, this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2418
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2419
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2420
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2421
TcpSocketBase::Retransmit ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2422
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2423
  m_nextTxSequence = m_txBuffer->HeadSequence (); // Start from highest Ack
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2424
  m_dupAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2425
  DoRetransmit (); // Retransmit the packet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2426
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2427
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2428
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2429
TcpSocketBase::DoRetransmit ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2430
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2431
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2432
  // Retransmit SYN packet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2433
  if (m_state == SYN_SENT)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2434
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2435
      if (m_cnCount > 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2436
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2437
          SendEmptyPacket (TcpHeader::SYN);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2438
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2439
      else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2440
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2441
          NotifyConnectionFailed ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2442
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2443
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2444
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2445
  // Retransmit non-data packet: Only if in FIN_WAIT_1 or CLOSING state
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2446
  if (m_txBuffer->Size () == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2447
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2448
      if (m_state == FIN_WAIT_1 || m_state == CLOSING)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2449
        { // Must have lost FIN, re-send
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2450
          SendEmptyPacket (TcpHeader::FIN);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2451
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2452
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2453
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2454
  // Retransmit a data packet: Call SendDataPacket
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2455
  NS_LOG_LOGIC ("TcpSocketBase " << this << " retxing seq " << m_txBuffer->HeadSequence ());
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2456
  uint32_t sz = SendDataPacket (m_txBuffer->HeadSequence (), m_segmentSize, true);
7611
d462369b70f1 Advance m_nextTxSequence upon retransmit after RTO (fixes bug 1112)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7610
diff changeset
  2457
  // In case of RTO, advance m_nextTxSequence
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2458
  m_nextTxSequence = std::max (m_nextTxSequence.Get (), m_txBuffer->HeadSequence () + sz);
7611
d462369b70f1 Advance m_nextTxSequence upon retransmit after RTO (fixes bug 1112)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7610
diff changeset
  2459
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2460
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2461
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2462
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2463
TcpSocketBase::CancelAllTimers ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2464
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2465
  m_retxEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2466
  m_persistEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2467
  m_delAckEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2468
  m_lastAckEvent.Cancel ();
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2469
  m_timewaitEvent.Cancel ();
11359
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2470
  m_sendPendingDataEvent.Cancel ();
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2471
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2472
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  2473
/* Move TCP to Time_Wait state and schedule a transition to Closed state */
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2474
void
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2475
TcpSocketBase::TimeWait ()
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2476
{
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2477
  NS_LOG_INFO (TcpStateName[m_state] << " -> TIME_WAIT");
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2478
  m_state = TIME_WAIT;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2479
  CancelAllTimers ();
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2480
  // Move from TIME_WAIT to CLOSED after 2*MSL. Max segment lifetime is 2 min
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2481
  // according to RFC793, p.28
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2482
  m_timewaitEvent = Simulator::Schedule (Seconds (2 * m_msl),
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2483
                                         &TcpSocketBase::CloseAndNotify, this);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2484
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2485
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  2486
/* Below are the attribute get/set functions */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2487
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2488
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2489
TcpSocketBase::SetSndBufSize (uint32_t size)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2490
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2491
  m_txBuffer->SetMaxBufferSize (size);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2492
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2493
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2494
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2495
TcpSocketBase::GetSndBufSize (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2496
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2497
  return m_txBuffer->MaxBufferSize ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2498
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2499
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2500
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2501
TcpSocketBase::SetRcvBufSize (uint32_t size)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2502
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2503
  m_rxBuffer->SetMaxBufferSize (size);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2504
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2505
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2506
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2507
TcpSocketBase::GetRcvBufSize (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2508
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2509
  return m_rxBuffer->MaxBufferSize ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2510
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2511
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2512
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2513
TcpSocketBase::SetSegSize (uint32_t size)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2514
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2515
  m_segmentSize = size;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2516
  NS_ABORT_MSG_UNLESS (m_state == CLOSED, "Cannot change segment size dynamically.");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2517
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2518
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2519
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2520
TcpSocketBase::GetSegSize (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2521
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2522
  return m_segmentSize;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2523
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2524
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2525
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2526
TcpSocketBase::SetConnTimeout (Time timeout)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2527
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2528
  m_cnTimeout = timeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2529
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2530
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2531
Time
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2532
TcpSocketBase::GetConnTimeout (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2533
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2534
  return m_cnTimeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2535
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2536
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2537
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2538
TcpSocketBase::SetConnCount (uint32_t count)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2539
{
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2540
  m_cnRetries = count;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2541
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2542
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2543
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2544
TcpSocketBase::GetConnCount (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2545
{
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2546
  return m_cnRetries;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2547
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2548
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2549
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2550
TcpSocketBase::SetDelAckTimeout (Time timeout)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2551
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2552
  m_delAckTimeout = timeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2553
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2554
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2555
Time
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2556
TcpSocketBase::GetDelAckTimeout (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2557
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2558
  return m_delAckTimeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2559
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2560
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2561
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2562
TcpSocketBase::SetDelAckMaxCount (uint32_t count)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2563
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2564
  m_delAckMaxCount = count;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2565
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2566
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2567
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2568
TcpSocketBase::GetDelAckMaxCount (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2569
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2570
  return m_delAckMaxCount;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2571
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2572
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2573
void
7619
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2574
TcpSocketBase::SetTcpNoDelay (bool noDelay)
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2575
{
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2576
  m_noDelay = noDelay;
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2577
}
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2578
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2579
bool
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2580
TcpSocketBase::GetTcpNoDelay (void) const
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2581
{
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2582
  return m_noDelay;
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2583
}
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2584
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2585
void
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2586
TcpSocketBase::SetPersistTimeout (Time timeout)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2587
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2588
  m_persistTimeout = timeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2589
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2590
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2591
Time
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2592
TcpSocketBase::GetPersistTimeout (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2593
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2594
  return m_persistTimeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2595
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2596
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2597
bool
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2598
TcpSocketBase::SetAllowBroadcast (bool allowBroadcast)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2599
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2600
  // Broadcast is not implemented. Return true only if allowBroadcast==false
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
  2601
  return (!allowBroadcast);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2602
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2603
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2604
bool
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2605
TcpSocketBase::GetAllowBroadcast (void) const
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2606
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2607
  return false;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2608
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2609
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2610
void
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2611
TcpSocketBase::ReadOptions (const TcpHeader& header)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2612
{
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2613
  NS_LOG_FUNCTION (this << header);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2614
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2615
  if ((header.GetFlags () & TcpHeader::SYN))
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2616
    {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2617
      if (m_winScalingEnabled)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2618
        {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2619
          m_winScalingEnabled = false;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2620
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2621
          if (header.HasOption (TcpOption::WINSCALE))
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2622
            {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2623
              m_winScalingEnabled = true;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2624
              ProcessOptionWScale (header.GetOption (TcpOption::WINSCALE));
11359
c2269e7c4f42 Bug 2067 - TCP performances drop when Advertised Window is larger than Sender Buffer size
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11259
diff changeset
  2625
              ScaleSsThresh (m_sndScaleFactor);
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2626
            }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2627
        }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2628
    }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2629
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2630
  m_timestampEnabled = false;
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2631
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2632
  if (header.HasOption (TcpOption::TS))
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2633
    {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2634
      m_timestampEnabled = true;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2635
      ProcessOptionTimestamp (header.GetOption (TcpOption::TS));
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2636
    }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2637
}
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2638
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2639
void
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2640
TcpSocketBase::AddOptions (TcpHeader& header)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2641
{
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2642
  NS_LOG_FUNCTION (this << header);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2643
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2644
  // The window scaling option is set only on SYN packets
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2645
  if (m_winScalingEnabled && (header.GetFlags () & TcpHeader::SYN))
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2646
    {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2647
      AddOptionWScale (header);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2648
    }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2649
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2650
  if (m_timestampEnabled)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2651
    {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2652
      AddOptionTimestamp (header);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2653
    }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2654
}
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2655
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2656
void
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2657
TcpSocketBase::ProcessOptionWScale (const Ptr<const TcpOption> option)
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2658
{
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2659
  NS_LOG_FUNCTION (this << option);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2660
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2661
  Ptr<const TcpOptionWinScale> ws = DynamicCast<const TcpOptionWinScale> (option);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2662
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2663
  // In naming, we do the contrary of RFC 1323. The received scaling factor
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2664
  // is Rcv.Wind.Scale (and not Snd.Wind.Scale)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2665
  m_rcvScaleFactor = ws->GetScale ();
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2666
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2667
  if (m_rcvScaleFactor > 14)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2668
    {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2669
      NS_LOG_WARN ("Possible error; m_rcvScaleFactor exceeds 14: " << m_rcvScaleFactor);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2670
      m_rcvScaleFactor = 14;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2671
    }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2672
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2673
  NS_LOG_INFO (m_node->GetId () << " Received a scale factor of " <<
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2674
                 static_cast<int> (m_rcvScaleFactor));
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2675
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2676
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2677
uint8_t
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2678
TcpSocketBase::CalculateWScale () const
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2679
{
10911
c224a92a02a2 add some logging
Tom Henderson <tomh@tomh.org>
parents: 10907
diff changeset
  2680
  NS_LOG_FUNCTION (this);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2681
  uint32_t maxSpace = m_rxBuffer->MaxBufferSize ();
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2682
  uint8_t scale = 0;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2683
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2684
  while (maxSpace > m_maxWinSize)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2685
    {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2686
      maxSpace = maxSpace >> 1;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2687
      ++scale;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2688
    }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2689
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2690
  if (scale > 14)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2691
    {
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2692
      NS_LOG_WARN ("Possible error; scale exceeds 14: " << scale);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2693
      scale = 14;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2694
    }
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2695
10911
c224a92a02a2 add some logging
Tom Henderson <tomh@tomh.org>
parents: 10907
diff changeset
  2696
  NS_LOG_INFO ("Node " << m_node->GetId () << " calculated wscale factor of " <<
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2697
               static_cast<int> (scale) << " for buffer size " << m_rxBuffer->MaxBufferSize ());
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2698
  return scale;
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2699
}
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2700
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2701
void
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2702
TcpSocketBase::AddOptionWScale (TcpHeader &header)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2703
{
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2704
  NS_LOG_FUNCTION (this << header);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2705
  NS_ASSERT(header.GetFlags () & TcpHeader::SYN);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2706
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2707
  Ptr<TcpOptionWinScale> option = CreateObject<TcpOptionWinScale> ();
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2708
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2709
  // In naming, we do the contrary of RFC 1323. The sended scaling factor
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2710
  // is Snd.Wind.Scale (and not Rcv.Wind.Scale)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2711
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2712
  m_sndScaleFactor = CalculateWScale ();
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2713
  option->SetScale (m_sndScaleFactor);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2714
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2715
  header.AppendOption (option);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2716
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2717
  NS_LOG_INFO (m_node->GetId () << " Send a scaling factor of " <<
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2718
                 static_cast<int> (m_sndScaleFactor));
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2719
}
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2720
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2721
void
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2722
TcpSocketBase::ProcessOptionTimestamp (const Ptr<const TcpOption> option)
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2723
{
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2724
  NS_LOG_FUNCTION (this << option);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2725
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2726
  Ptr<const TcpOptionTS> ts = DynamicCast<const TcpOptionTS> (option);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2727
  m_timestampToEcho = ts->GetTimestamp ();
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2728
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2729
  NS_LOG_INFO (m_node->GetId () << " Got timestamp=" <<
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2730
               m_timestampToEcho << " and Echo="     << ts->GetEcho ());
10885
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2731
}
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2732
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2733
void
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2734
TcpSocketBase::AddOptionTimestamp (TcpHeader& header)
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2735
{
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2736
  NS_LOG_FUNCTION (this << header);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2737
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2738
  Ptr<TcpOptionTS> option = CreateObject<TcpOptionTS> ();
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2739
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2740
  option->SetTimestamp (TcpOptionTS::NowToTsValue ());
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2741
  option->SetEcho (m_timestampToEcho);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2742
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2743
  header.AppendOption (option);
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2744
  NS_LOG_INFO (m_node->GetId () << " Add option TS, ts=" <<
462d70f54ada Support for basic TCP options, window scale, and timestamps, based on original code proposal by Adrian S.-W. Tam
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10771
diff changeset
  2745
               option->GetTimestamp () << " echo=" << m_timestampToEcho);
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2746
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2747
11362
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2748
void TcpSocketBase::UpdateWindowSize (const TcpHeader &header)
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2749
{
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2750
  NS_LOG_FUNCTION (this << header);
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2751
  //  If the connection is not established, the window size is always
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2752
  //  updated
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2753
  uint32_t receivedWindow = header.GetWindowSize ();
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2754
  receivedWindow <<= m_rcvScaleFactor;
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2755
  NS_LOG_DEBUG ("Received (scaled) window is " << receivedWindow << " bytes");
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2756
  if (m_state < ESTABLISHED)
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2757
    {
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2758
      m_rWnd = receivedWindow;
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2759
      NS_LOG_DEBUG ("State less than ESTABLISHED; updating rWnd to " << m_rWnd);
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2760
      return;
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2761
    }
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2762
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2763
  // Test for conditions that allow updating of the window
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2764
  // 1) segment contains new data (advancing the right edge of the receive 
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2765
  // buffer), 
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2766
  // 2) segment does not contain new data but the segment acks new data 
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2767
  // (highest sequence number acked advances), or
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2768
  // 3) the advertised window is larger than the current send window
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2769
  bool update = false;
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2770
  if (header.GetAckNumber () == m_highRxAckMark && receivedWindow > m_rWnd)
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2771
    {
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2772
      // right edge of the send window is increased (window update)
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2773
      update = true;
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2774
    }
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2775
  if (header.GetAckNumber () > m_highRxAckMark)
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2776
    {
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2777
      m_highRxAckMark = header.GetAckNumber ();
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2778
      update = true;
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2779
    }
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2780
  if (header.GetSequenceNumber () > m_highRxMark)
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2781
    {
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2782
      m_highRxMark = header.GetSequenceNumber ();
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2783
      update = true;
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2784
    }
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2785
  if (update == true)
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2786
    {
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2787
      m_rWnd = receivedWindow;
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2788
      NS_LOG_DEBUG ("updating rWnd to " << m_rWnd);
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2789
    }
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2790
}
917793d13817 bug 2058: TCP window update can shrink the Left Edge of the window which is a bug (patch based on earlier contribution from Evgeny Evstropov)
Tom Henderson <tomh@tomh.org>
parents: 11359
diff changeset
  2791
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2792
void
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2793
TcpSocketBase::SetMinRto (Time minRto)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2794
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2795
  NS_LOG_FUNCTION (this << minRto);
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2796
  m_minRto = minRto;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2797
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2798
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2799
Time
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2800
TcpSocketBase::GetMinRto (void) const
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2801
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2802
  return m_minRto;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2803
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2804
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2805
void
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2806
TcpSocketBase::SetClockGranularity (Time clockGranularity)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2807
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2808
  NS_LOG_FUNCTION (this << clockGranularity);
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2809
  m_clockGranularity = clockGranularity;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2810
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2811
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2812
Time
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2813
TcpSocketBase::GetClockGranularity (void) const
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2814
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2815
  return m_clockGranularity;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2816
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2817
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2818
Ptr<TcpTxBuffer>
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2819
TcpSocketBase::GetTxBuffer (void) const
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2820
{
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2821
  return m_txBuffer;
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2822
}
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2823
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2824
Ptr<TcpRxBuffer>
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2825
TcpSocketBase::GetRxBuffer (void) const
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2826
{
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2827
  return m_rxBuffer;
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2828
}
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2829
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2830
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2831
//RttHistory methods
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2832
RttHistory::RttHistory (SequenceNumber32 s, uint32_t c, Time t)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2833
  : seq (s), count (c), time (t), retx (false)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2834
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2835
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2836
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2837
RttHistory::RttHistory (const RttHistory& h)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2838
  : seq (h.seq), count (h.count), time (h.time), retx (h.retx)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2839
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2840
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2841
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2842
} // namespace ns3