src/internet/model/tcp-socket-base.cc
author Natale Patriciello <natale.patriciello@gmail.com>
Thu, 03 Sep 2015 21:20:53 -0700
changeset 11633 6b74df04cf44
parent 11632 88d6e64c778c
permissions -rw-r--r--
bug 2174: m_rWnd not updated when segments without ACK are received
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),
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11513
diff changeset
   144
                     "ns3::TracedValueCallback::Uint32")
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")
11511
2c614cf0b5bd Moved cWnd and ssThresh inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11510
diff changeset
   153
    .AddTraceSource ("CongestionWindow",
2c614cf0b5bd Moved cWnd and ssThresh inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11510
diff changeset
   154
                     "The TCP connection's congestion window",
2c614cf0b5bd Moved cWnd and ssThresh inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11510
diff changeset
   155
                     MakeTraceSourceAccessor (&TcpSocketBase::m_cWnd),
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11513
diff changeset
   156
                     "ns3::TracedValueCallback::Uint32")
11511
2c614cf0b5bd Moved cWnd and ssThresh inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11510
diff changeset
   157
    .AddTraceSource ("SlowStartThreshold",
2c614cf0b5bd Moved cWnd and ssThresh inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11510
diff changeset
   158
                     "TCP slow start threshold (bytes)",
2c614cf0b5bd Moved cWnd and ssThresh inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11510
diff changeset
   159
                     MakeTraceSourceAccessor (&TcpSocketBase::m_ssThresh),
11598
b4d1339b4913 Refactor TracedValue callback function signatures.
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 11513
diff changeset
   160
                     "ns3::TracedValueCallback::Uint32")
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   161
  ;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   162
  return tid;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   163
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   164
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   165
TcpSocketBase::TcpSocketBase (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   166
  : m_dupAckCount (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   167
    m_delAckCount (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   168
    m_endPoint (0),
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   169
    m_endPoint6 (0),
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   170
    m_node (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   171
    m_tcp (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   172
    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
   173
    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
   174
    // Change this for non-zero initial sequence number
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   175
    m_highTxMark (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   176
    m_rxBuffer (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   177
    m_txBuffer (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   178
    m_state (CLOSED),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   179
    m_errno (ERROR_NOTERROR),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   180
    m_closeNotified (false),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   181
    m_closeOnEmpty (false),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   182
    m_shutdownSend (false),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   183
    m_shutdownRecv (false),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   184
    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
   185
    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
   186
    // 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
   187
    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
   188
    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
   189
    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
   190
    m_sndScaleFactor (0),
10907
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   191
    m_rcvScaleFactor (0),
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   192
    m_timestampEnabled (true),
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   193
    m_timestampToEcho (0)
10907
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   194
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   195
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   196
  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
   197
  m_rxBuffer = CreateObject<TcpRxBuffer> ();
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   198
  m_txBuffer = CreateObject<TcpTxBuffer> ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   199
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   200
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   201
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
   202
  : 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
   203
    //copy object::m_tid and socket::callbacks
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   204
    m_dupAckCount (sock.m_dupAckCount),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   205
    m_delAckCount (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   206
    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
   207
    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
   208
    m_cnRetries (sock.m_cnRetries),
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   209
    m_delAckTimeout (sock.m_delAckTimeout),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   210
    m_persistTimeout (sock.m_persistTimeout),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   211
    m_cnTimeout (sock.m_cnTimeout),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   212
    m_endPoint (0),
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   213
    m_endPoint6 (0),
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   214
    m_node (sock.m_node),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   215
    m_tcp (sock.m_tcp),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   216
    m_rtt (0),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   217
    m_nextTxSequence (sock.m_nextTxSequence),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   218
    m_highTxMark (sock.m_highTxMark),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   219
    m_state (sock.m_state),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   220
    m_errno (sock.m_errno),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   221
    m_closeNotified (sock.m_closeNotified),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   222
    m_closeOnEmpty (sock.m_closeOnEmpty),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   223
    m_shutdownSend (sock.m_shutdownSend),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   224
    m_shutdownRecv (sock.m_shutdownRecv),
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   225
    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
   226
    m_msl (sock.m_msl),
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   227
    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
   228
    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
   229
    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
   230
    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
   231
    m_highRxAckMark (sock.m_highRxAckMark),
11511
2c614cf0b5bd Moved cWnd and ssThresh inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11510
diff changeset
   232
    m_cWnd (sock.m_cWnd),
2c614cf0b5bd Moved cWnd and ssThresh inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11510
diff changeset
   233
    m_ssThresh (sock.m_ssThresh),
11512
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   234
    m_initialCWnd (sock.m_initialCWnd),
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   235
    m_initialSsThresh (sock.m_initialSsThresh),
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
   236
    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
   237
    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
   238
    m_rcvScaleFactor (sock.m_rcvScaleFactor),
10907
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   239
    m_timestampEnabled (sock.m_timestampEnabled),
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
   240
    m_timestampToEcho (sock.m_timestampToEcho)
10907
1ab4df5685aa TCP Options - Valgrind fixes
Natale Patriciello <natale.patriciello@gmail.com>
parents: 10885
diff changeset
   241
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   242
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   243
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   244
  NS_LOG_LOGIC ("Invoked the copy constructor");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   245
  // Copy the rtt estimator if it is set
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   246
  if (sock.m_rtt)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   247
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   248
      m_rtt = sock.m_rtt->Copy ();
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
  // Reset all callbacks to null
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   251
  Callback<void, Ptr< Socket > > vPS = MakeNullCallback<void, Ptr<Socket> > ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   252
  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
   253
  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
   254
  SetConnectCallback (vPS, vPS);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   255
  SetDataSentCallback (vPSUI);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   256
  SetSendCallback (vPSUI);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   257
  SetRecvCallback (vPS);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   258
  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
   259
  m_rxBuffer = CopyObject (sock.m_rxBuffer);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   260
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   261
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   262
TcpSocketBase::~TcpSocketBase (void)
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_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   265
  m_node = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   266
  if (m_endPoint != 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   267
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   268
      NS_ASSERT (m_tcp != 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   269
      /*
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   270
       * 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
   271
       * DestroyCallback is set to TcpSocketBase::Destroy. If we called
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   272
       * m_tcp->DeAllocate, it wil destroy its Ipv4EndpointDemux::DeAllocate,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   273
       * which in turn destroys my m_endPoint, and in turn invokes
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   274
       * TcpSocketBase::Destroy to nullify m_node, m_endPoint, and m_tcp.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   275
       */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   276
      NS_ASSERT (m_endPoint != 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   277
      m_tcp->DeAllocate (m_endPoint);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   278
      NS_ASSERT (m_endPoint == 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   279
    }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   280
  if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   281
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   282
      NS_ASSERT (m_tcp != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   283
      NS_ASSERT (m_endPoint6 != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   284
      m_tcp->DeAllocate (m_endPoint6);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   285
      NS_ASSERT (m_endPoint6 == 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   286
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   287
  m_tcp = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   288
  CancelAllTimers ();
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   291
/* Associate a node with this TCP socket */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   292
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   293
TcpSocketBase::SetNode (Ptr<Node> node)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   294
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   295
  m_node = node;
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   298
/* 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
   299
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   300
TcpSocketBase::SetTcp (Ptr<TcpL4Protocol> tcp)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   301
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   302
  m_tcp = tcp;
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   305
/* Set an RTT estimator with this socket */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   306
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   307
TcpSocketBase::SetRtt (Ptr<RttEstimator> rtt)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   308
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   309
  m_rtt = rtt;
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   312
/* Inherit from Socket class: Returns error code */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   313
enum Socket::SocketErrno
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   314
TcpSocketBase::GetErrno (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   315
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   316
  return m_errno;
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   319
/* Inherit from Socket class: Returns socket type, NS3_SOCK_STREAM */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   320
enum Socket::SocketType
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   321
TcpSocketBase::GetSocketType (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   322
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   323
  return NS3_SOCK_STREAM;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   324
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   325
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   326
/* Inherit from Socket class: Returns associated node */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   327
Ptr<Node>
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   328
TcpSocketBase::GetNode (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   329
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   330
  NS_LOG_FUNCTION_NOARGS ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   331
  return m_node;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   332
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   333
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   334
/* 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
   335
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   336
TcpSocketBase::Bind (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   337
{
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   338
  NS_LOG_FUNCTION (this);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   339
  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
   340
  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
   341
    {
bf446d9feecc Bug 1163 - Ipv4EndPointDemux::AllocateEphemeralPort forget to increment the port
John Abraham <john.abraham@gatech.edu>
parents: 7440
diff changeset
   342
      m_errno = ERROR_ADDRNOTAVAIL;
bf446d9feecc Bug 1163 - Ipv4EndPointDemux::AllocateEphemeralPort forget to increment the port
John Abraham <john.abraham@gatech.edu>
parents: 7440
diff changeset
   343
      return -1;
bf446d9feecc Bug 1163 - Ipv4EndPointDemux::AllocateEphemeralPort forget to increment the port
John Abraham <john.abraham@gatech.edu>
parents: 7440
diff changeset
   344
    }
10697
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   345
11500
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
   346
  m_tcp->AddSocket(this);
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
   347
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   348
  return SetupCallback ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   349
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   350
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   351
int
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   352
TcpSocketBase::Bind6 (void)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   353
{
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   354
  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
   355
  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
   356
  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
   357
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   358
      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
   359
      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
   360
    }
10697
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   361
11500
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
   362
  m_tcp->AddSocket(this);
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
   363
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   364
  return SetupCallback ();
7717
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   367
/* 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
   368
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   369
TcpSocketBase::Bind (const Address &address)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   370
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   371
  NS_LOG_FUNCTION (this << address);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   372
  if (InetSocketAddress::IsMatchingType (address))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   373
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   374
      InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   375
      Ipv4Address ipv4 = transport.GetIpv4 ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   376
      uint16_t port = transport.GetPort ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   377
      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 ();
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 (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
      else if (ipv4 != Ipv4Address::GetAny () && port == 0)
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_endPoint = m_tcp->Allocate (ipv4);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   388
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   389
      else if (ipv4 != Ipv4Address::GetAny () && port != 0)
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
          m_endPoint = m_tcp->Allocate (ipv4, port);
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
      if (0 == m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   394
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   395
          m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   396
          return -1;
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
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   399
  else if (Inet6SocketAddress::IsMatchingType (address))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   400
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   401
      Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   402
      Ipv6Address ipv6 = transport.GetIpv6 ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   403
      uint16_t port = transport.GetPort ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   404
      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 ();
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 (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
      else if (ipv6 != Ipv6Address::GetAny () && port == 0)
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_endPoint6 = m_tcp->Allocate6 (ipv6);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   415
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   416
      else if (ipv6 != Ipv6Address::GetAny () && port != 0)
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
          m_endPoint6 = m_tcp->Allocate6 (ipv6, port);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   419
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   420
      if (0 == m_endPoint6)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   421
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   422
          m_errno = port ? ERROR_ADDRINUSE : ERROR_ADDRNOTAVAIL;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   423
          return -1;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   424
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   425
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   426
  else
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   427
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   428
      m_errno = ERROR_INVAL;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   429
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   430
    }
10697
323f8bb2ec61 Bug1829
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10694
diff changeset
   431
11500
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
   432
  m_tcp->AddSocket(this);
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
   433
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   434
  NS_LOG_LOGIC ("TcpSocketBase " << this << " got an endpoint: " << m_endPoint);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   435
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   436
  return SetupCallback ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   437
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   438
11512
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   439
void
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   440
TcpSocketBase::InitializeCwnd (void)
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   441
{
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   442
  m_cWnd = m_initialCWnd * m_segmentSize;
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   443
  m_ssThresh = m_initialSsThresh;
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   444
}
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   445
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   446
void
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   447
TcpSocketBase::SetInitialSSThresh (uint32_t threshold)
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   448
{
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   449
  NS_ABORT_MSG_UNLESS (m_state == CLOSED,
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   450
    "TcpSocketBase::SetSSThresh() cannot change initial ssThresh after connection started.");
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   451
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   452
  m_initialSsThresh = threshold;
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   453
}
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   454
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   455
uint32_t
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   456
TcpSocketBase::GetInitialSSThresh (void) const
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   457
{
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   458
  return m_initialSsThresh;
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   459
}
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   460
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   461
void
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   462
TcpSocketBase::SetInitialCwnd (uint32_t cwnd)
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   463
{
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   464
  NS_ABORT_MSG_UNLESS (m_state == CLOSED,
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   465
    "TcpSocketBase::SetInitialCwnd() cannot change initial cwnd after connection started.");
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   466
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   467
  m_initialCWnd = cwnd;
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   468
}
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   469
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   470
uint32_t
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   471
TcpSocketBase::GetInitialCwnd (void) const
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   472
{
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   473
  return m_initialCWnd;
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   474
}
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   475
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   476
void
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   477
TcpSocketBase::ScaleSsThresh (uint8_t scaleFactor)
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   478
{
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   479
  m_ssThresh <<= scaleFactor;
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   480
}
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   481
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   482
/* 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
   483
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   484
TcpSocketBase::Connect (const Address & address)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   485
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   486
  NS_LOG_FUNCTION (this << address);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   487
11512
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   488
  InitializeCwnd ();
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   489
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   490
  // 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
   491
  if (InetSocketAddress::IsMatchingType (address) && m_endPoint6 == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   492
    {
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   493
      if (m_endPoint == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   494
        {
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   495
          if (Bind () == -1)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   496
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   497
              NS_ASSERT (m_endPoint == 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   498
              return -1; // Bind() failed
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   499
            }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   500
          NS_ASSERT (m_endPoint != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   501
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   502
      InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   503
      m_endPoint->SetPeer (transport.GetIpv4 (), transport.GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   504
      m_endPoint6 = 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   505
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   506
      // 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
   507
      if (SetupEndpoint () != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   508
        { // Route to destination does not exist
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   509
          return -1;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   510
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   511
    }
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   512
  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
   513
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   514
      // 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
   515
      // a v4 address and re-call this function
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   516
      Inet6SocketAddress transport = Inet6SocketAddress::ConvertFrom (address);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   517
      Ipv6Address v6Addr = transport.GetIpv6 ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   518
      if (v6Addr.IsIpv4MappedAddress () == true)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   519
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   520
          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
   521
          return Connect (InetSocketAddress (v4Addr, transport.GetPort ()));
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   522
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   523
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   524
      if (m_endPoint6 == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   525
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   526
          if (Bind6 () == -1)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   527
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   528
              NS_ASSERT (m_endPoint6 == 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   529
              return -1; // Bind() failed
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   530
            }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   531
          NS_ASSERT (m_endPoint6 != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   532
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   533
      m_endPoint6->SetPeer (v6Addr, transport.GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   534
      m_endPoint = 0;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   535
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   536
      // 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
   537
      if (SetupEndpoint6 () != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   538
        { // Route to destination does not exist
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   539
          return -1;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   540
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   541
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   542
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   543
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   544
      m_errno = ERROR_INVAL;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   545
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   546
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   547
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   548
  // 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
   549
  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
   550
  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
   551
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   552
  // DoConnect() will do state-checking and send a SYN packet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   553
  return DoConnect ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   554
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   555
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   556
/* 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
   557
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   558
TcpSocketBase::Listen (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   559
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   560
  NS_LOG_FUNCTION (this);
11512
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   561
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   562
  InitializeCwnd ();
c0e78011217c Initialize cWnd and ssTh in TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11511
diff changeset
   563
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   564
  // 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
   565
  if (m_state != CLOSED)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   566
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   567
      m_errno = ERROR_INVAL;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   568
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   569
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   570
  // In other cases, set the state to LISTEN and done
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   571
  NS_LOG_INFO ("CLOSED -> LISTEN");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   572
  m_state = LISTEN;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   573
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   574
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   575
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   576
/* 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
   577
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   578
TcpSocketBase::Close (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   579
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   580
  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
   581
  /// \internal
02e3d2d7d7e1 Link to bug num in bug database with \bugid{num}
Peter D. Barnes, Jr. <barnes26@llnl.gov>
parents: 9258
diff changeset
   582
  /// 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
   583
  /// \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
   584
  if (m_rxBuffer->Size () != 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   585
    {
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   586
      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
   587
      SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   588
      return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   589
    }
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   590
 
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   591
  if (m_txBuffer->SizeFromSequence (m_nextTxSequence) > 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   592
    { // App close with pending data must wait until all data transmitted
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   593
      if (m_closeOnEmpty == false)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   594
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   595
          m_closeOnEmpty = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   596
          NS_LOG_INFO ("Socket " << this << " deferring close, state " << TcpStateName[m_state]);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   597
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   598
      return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   599
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   600
  return DoClose ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   601
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   602
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   603
/* Inherit from Socket class: Signal a termination of send */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   604
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   605
TcpSocketBase::ShutdownSend (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   606
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   607
  NS_LOG_FUNCTION (this);
9258
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
  //this prevents data from being added to the buffer
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   610
  m_shutdownSend = true;
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   611
  m_closeOnEmpty = true;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   612
  //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
   613
  //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
   614
  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
   615
    {
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   616
      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
   617
        {
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   618
          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
   619
          SendEmptyPacket (TcpHeader::FIN);  
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   620
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   621
          if (m_state == ESTABLISHED)
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   622
            { // 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
   623
              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
   624
              m_state = FIN_WAIT_1;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   625
            }
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   626
          else
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   627
            { // 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
   628
              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
   629
              m_state = LAST_ACK;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   630
            }  
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   631
        }
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   632
    }
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   633
 
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   634
  return 0;
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: Signal a termination of receive */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   638
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   639
TcpSocketBase::ShutdownRecv (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   640
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   641
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   642
  m_shutdownRecv = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   643
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   644
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   645
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   646
/* 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
   647
    Packet has no TCP header. Invoked by upper-layer application */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   648
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   649
TcpSocketBase::Send (Ptr<Packet> p, uint32_t flags)
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
  NS_LOG_FUNCTION (this << p);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   652
  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
   653
  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
   654
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   655
      // 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
   656
      if (!m_txBuffer->Add (p))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   657
        { // TxBuffer overflow, send failed
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   658
          m_errno = ERROR_MSGSIZE;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   659
          return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   660
        }
9258
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   661
      if (m_shutdownSend)
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   662
        {
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   663
          m_errno = ERROR_SHUTDOWN;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   664
          return -1;
620eeaa0e173 bug 1502 Shutdown on tcp socket seems to misbehave
Brian Swenson <bswenson3@gatech.edu>
parents: 9145
diff changeset
   665
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   666
      // 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
   667
      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
   668
      if (m_state == ESTABLISHED || m_state == CLOSE_WAIT)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   669
        { // 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
   670
          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
   671
            {
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
   672
              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
   673
            }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   674
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   675
      return p->GetSize ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   676
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   677
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   678
    { // Connection not established yet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   679
      m_errno = ERROR_NOTCONN;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   680
      return -1; // Send failure
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   681
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   682
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   683
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   684
/* 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
   685
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   686
TcpSocketBase::SendTo (Ptr<Packet> p, uint32_t flags, const Address &address)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   687
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   688
  return Send (p, flags); // SendTo() and Send() are the same
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   689
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   690
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   691
/* 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
   692
   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
   693
Ptr<Packet>
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   694
TcpSocketBase::Recv (uint32_t maxSize, uint32_t flags)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   695
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   696
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   697
  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
   698
  if (m_rxBuffer->Size () == 0 && m_state == CLOSE_WAIT)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   699
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   700
      return Create<Packet> (); // Send EOF on connection close
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   701
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
   702
  Ptr<Packet> outPacket = m_rxBuffer->Extract (maxSize);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   703
  if (outPacket != 0 && outPacket->GetSize () != 0)
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
      SocketAddressTag tag;
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   706
      if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   707
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   708
          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
   709
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   710
      else if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   711
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   712
          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
   713
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   714
      outPacket->AddPacketTag (tag);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   715
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   716
  return outPacket;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   717
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   718
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   719
/* 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
   720
Ptr<Packet>
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   721
TcpSocketBase::RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   722
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   723
  NS_LOG_FUNCTION (this << maxSize << flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   724
  Ptr<Packet> packet = Recv (maxSize, flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   725
  // 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
   726
  if (packet != 0 && packet->GetSize () != 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   727
    {
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   728
      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
   729
        {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   730
          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
   731
        }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   732
      else if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   733
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   734
          fromAddress = Inet6SocketAddress (m_endPoint6->GetPeerAddress (), m_endPoint6->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   735
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   736
      else
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   737
        {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   738
          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
   739
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   740
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   741
  return packet;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   742
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   743
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   744
/* 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
   745
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   746
TcpSocketBase::GetTxAvailable (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   747
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   748
  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
   749
  return m_txBuffer->Available ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   750
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   751
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   752
/* 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
   753
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   754
TcpSocketBase::GetRxAvailable (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   755
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   756
  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
   757
  return m_rxBuffer->Available ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   758
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   759
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   760
/* Inherit from Socket class: Return local address:port */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   761
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   762
TcpSocketBase::GetSockName (Address &address) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   763
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   764
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   765
  if (m_endPoint != 0)
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
      address = InetSocketAddress (m_endPoint->GetLocalAddress (), m_endPoint->GetLocalPort ());
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
  else if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   770
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   771
      address = Inet6SocketAddress (m_endPoint6->GetLocalAddress (), m_endPoint6->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   772
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   773
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   774
    { // 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
   775
      // in which case, behavior is unspecified
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   776
      // Should this return an InetSocketAddress or an Inet6SocketAddress?
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   777
      address = InetSocketAddress (Ipv4Address::GetZero (), 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   778
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   779
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   780
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   781
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   782
/* 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
   783
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   784
TcpSocketBase::BindToNetDevice (Ptr<NetDevice> netdevice)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   785
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   786
  NS_LOG_FUNCTION (netdevice);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   787
  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
   788
  if (m_endPoint == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   789
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   790
      if (Bind () == -1)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   791
        {
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   792
          NS_ASSERT (m_endPoint == 0);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   793
          return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   794
        }
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   795
      NS_ASSERT (m_endPoint != 0);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   796
    }
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   797
  m_endPoint->BindToNetDevice (netdevice);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   798
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   799
  if (m_endPoint6 == 0)
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   800
    {
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   801
      if (Bind6 () == -1)
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   802
        {
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   803
          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
   804
          return;
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   805
        }
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   806
      NS_ASSERT (m_endPoint6 != 0);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   807
    }
10933
7442f5603ef4 Bug 1824 - L4 protocol sockets should support BindToNetDevice over IPv6
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10912
diff changeset
   808
  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
   809
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   810
  return;
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   813
/* 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
   814
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   815
TcpSocketBase::SetupCallback (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   816
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   817
  NS_LOG_FUNCTION (this);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   818
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   819
  if (m_endPoint == 0 && m_endPoint6 == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   820
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   821
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   822
    }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   823
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   824
    {
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   825
      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
   826
      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
   827
      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
   828
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   829
  if (m_endPoint6 != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   830
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   831
      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
   832
      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
   833
      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
   834
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   835
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   836
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   837
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   838
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   839
/* 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
   840
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   841
TcpSocketBase::DoConnect (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   842
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   843
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   844
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   845
  // 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
   846
  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
   847
    { // send a SYN packet and change state into SYN_SENT
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   848
      SendEmptyPacket (TcpHeader::SYN);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   849
      NS_LOG_INFO (TcpStateName[m_state] << " -> SYN_SENT");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   850
      m_state = SYN_SENT;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   851
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   852
  else if (m_state != TIME_WAIT)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   853
    { // 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
   854
      // 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
   855
      SendRST ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   856
      CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   857
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   858
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   859
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   860
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   861
/* 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
   862
    flags depended on the current m_state. */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   863
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   864
TcpSocketBase::DoClose (void)
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
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   867
  switch (m_state)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   868
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   869
    case SYN_RCVD:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   870
    case ESTABLISHED:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   871
      // send FIN to close the peer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   872
      SendEmptyPacket (TcpHeader::FIN);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   873
      NS_LOG_INFO ("ESTABLISHED -> FIN_WAIT_1");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   874
      m_state = FIN_WAIT_1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   875
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   876
    case CLOSE_WAIT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   877
      // send FIN+ACK to close the peer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   878
      SendEmptyPacket (TcpHeader::FIN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   879
      NS_LOG_INFO ("CLOSE_WAIT -> LAST_ACK");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   880
      m_state = LAST_ACK;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   881
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   882
    case SYN_SENT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   883
    case CLOSING:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   884
      // 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
   885
      SendRST ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   886
      CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   887
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   888
    case LISTEN:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   889
    case LAST_ACK:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   890
      // 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
   891
      CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   892
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   893
    case CLOSED:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   894
    case FIN_WAIT_1:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   895
    case FIN_WAIT_2:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   896
    case TIME_WAIT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   897
    default: /* mute compiler */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   898
      // Do nothing in these four states
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   899
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   900
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   901
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   902
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   903
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   904
/* 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
   905
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   906
TcpSocketBase::CloseAndNotify (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   907
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   908
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   909
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   910
  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
   911
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
   912
      NotifyNormalClose ();
11044
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
   913
      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
   914
    }
10694
4af272d94cfd Bug 1791
Brian Swenson <bswenson3@gatech.edu>
parents: 10652
diff changeset
   915
11044
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
   916
  NS_LOG_INFO (TcpStateName[m_state] << " -> CLOSED");
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
   917
  m_state = CLOSED;
11040
cd2eda848730 bug 1791: TCP Endpoint never deallocates when closing
Pedro Silva <pmms@inesctec.pt>
parents: 10978
diff changeset
   918
  DeallocateEndPoint ();  
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   919
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   920
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   921
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   922
/* 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
   923
    accpet */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   924
bool
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   925
TcpSocketBase::OutOfRange (SequenceNumber32 head, SequenceNumber32 tail) const
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   926
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   927
  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
   928
    { // Rx buffer in these states are not initialized.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   929
      return false;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   930
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   931
  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
   932
    { // 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
   933
      // 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
   934
      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
   935
    }
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
   936
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   937
  // 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
   938
  return (tail < m_rxBuffer->NextRxSequence () || m_rxBuffer->MaxRxSequence () <= head);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   939
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   940
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
   941
/* 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
   942
    the TCP. This function is registered as the "RxCallback" function in
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   943
    SetupCallback(), which invoked by Bind(), and CompleteFork() */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   944
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   945
TcpSocketBase::ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   946
                          Ptr<Ipv4Interface> incomingInterface)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
   947
{
11508
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   948
  NS_LOG_LOGIC ("Socket " << this << " forward up " <<
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   949
                m_endPoint->GetPeerAddress () <<
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   950
                ":" << m_endPoint->GetPeerPort () <<
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   951
                " to " << m_endPoint->GetLocalAddress () <<
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   952
                ":" << m_endPoint->GetLocalPort ());
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   953
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   954
  Address fromAddress = InetSocketAddress (header.GetSource (), port);
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   955
  Address toAddress = InetSocketAddress (header.GetDestination (),
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   956
                                         m_endPoint->GetLocalPort ());
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   957
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   958
  DoForwardUp (packet, fromAddress, toAddress);
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   959
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
   960
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   961
void
11508
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   962
TcpSocketBase::ForwardUp6 (Ptr<Packet> packet, Ipv6Header header, uint16_t port,
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   963
                           Ptr<Ipv6Interface> incomingInterface)
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   964
{
11508
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   965
  NS_LOG_LOGIC ("Socket " << this << " forward up " <<
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   966
                m_endPoint6->GetPeerAddress () <<
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   967
                ":" << m_endPoint6->GetPeerPort () <<
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   968
                " to " << m_endPoint6->GetLocalAddress () <<
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   969
                ":" << m_endPoint6->GetLocalPort ());
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   970
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   971
  Address fromAddress = Inet6SocketAddress (header.GetSourceAddress (), port);
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   972
  Address toAddress = Inet6SocketAddress (header.GetDestinationAddress (),
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   973
                                          m_endPoint6->GetLocalPort ());
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   974
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
   975
  DoForwardUp (packet, fromAddress, toAddress);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   976
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
   977
9095
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   978
void
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   979
TcpSocketBase::ForwardIcmp (Ipv4Address icmpSource, uint8_t icmpTtl,
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   980
                            uint8_t icmpType, uint8_t icmpCode,
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   981
                            uint32_t icmpInfo)
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   982
{
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   983
  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
   984
                   (uint32_t)icmpCode << icmpInfo);
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   985
  if (!m_icmpCallback.IsNull ())
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   986
    {
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   987
      m_icmpCallback (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   988
    }
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   989
}
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   990
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   991
void
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   992
TcpSocketBase::ForwardIcmp6 (Ipv6Address icmpSource, uint8_t icmpTtl,
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   993
                            uint8_t icmpType, uint8_t icmpCode,
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   994
                            uint32_t icmpInfo)
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   995
{
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   996
  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
   997
                   (uint32_t)icmpCode << icmpInfo);
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   998
  if (!m_icmpCallback6.IsNull ())
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
   999
    {
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
  1000
      m_icmpCallback6 (icmpSource, icmpTtl, icmpType, icmpCode, icmpInfo);
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
  1001
    }
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
  1002
}
8462a1160246 bug 1359 TCP cannot receive ICMP
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 9078
diff changeset
  1003
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1004
void
11508
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
  1005
TcpSocketBase::DoForwardUp (Ptr<Packet> packet, const Address &fromAddress,
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
  1006
                            const Address &toAddress)
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1007
{
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1008
  // Peel off TCP header and do validity checking
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1009
  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
  1010
  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
  1011
  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
  1012
    {
e329871a431f prevent TcpHeader::Deserialize() from asserting; fix a few small bugs in option code
Tom Henderson <tomh@tomh.org>
parents: 10933
diff changeset
  1013
      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
  1014
      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
  1015
    }
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
  1016
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
  1017
  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
  1018
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1019
  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
  1020
    {
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1021
      EstimateRtt (tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1022
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1023
7622
f2e5d5201044 TcpSocketBase improved out of range checking
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7619
diff changeset
  1024
  // 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
  1025
  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
  1026
      && OutOfRange (tcpHeader.GetSequenceNumber (), tcpHeader.GetSequenceNumber () + packet->GetSize ()))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1027
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1028
      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
  1029
                    " 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
  1030
                    ":" << 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
  1031
                    ") 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
  1032
                    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
  1033
      // 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
  1034
      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
  1035
        {
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
  1036
          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
  1037
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1038
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1039
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1040
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
  1041
  // 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
  1042
  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
  1043
    { // 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
  1044
      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
  1045
      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
  1046
    }
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
  1047
  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
  1048
    {
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
  1049
      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
  1050
    }
11633
6b74df04cf44 bug 2174: m_rWnd not updated when segments without ACK are received
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11632
diff changeset
  1051
  else if (tcpHeader.GetFlags () & TcpHeader::SYN)
6b74df04cf44 bug 2174: m_rWnd not updated when segments without ACK are received
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11632
diff changeset
  1052
    {
6b74df04cf44 bug 2174: m_rWnd not updated when segments without ACK are received
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11632
diff changeset
  1053
      /* The window field in a segment where the SYN bit is set (i.e., a <SYN>
6b74df04cf44 bug 2174: m_rWnd not updated when segments without ACK are received
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11632
diff changeset
  1054
       * or <SYN,ACK>) MUST NOT be scaled (from RFC 7323 page 9). But should be
6b74df04cf44 bug 2174: m_rWnd not updated when segments without ACK are received
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11632
diff changeset
  1055
       * saved anyway..
6b74df04cf44 bug 2174: m_rWnd not updated when segments without ACK are received
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11632
diff changeset
  1056
       */
6b74df04cf44 bug 2174: m_rWnd not updated when segments without ACK are received
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11632
diff changeset
  1057
      m_rWnd = tcpHeader.GetWindowSize ();
6b74df04cf44 bug 2174: m_rWnd not updated when segments without ACK are received
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11632
diff changeset
  1058
    }
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
  1059
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1060
  // TCP state machine code in different process functions
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1061
  // 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
  1062
  switch (m_state)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1063
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1064
    case ESTABLISHED:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1065
      ProcessEstablished (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1066
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1067
    case LISTEN:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1068
      ProcessListen (packet, tcpHeader, fromAddress, toAddress);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1069
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1070
    case TIME_WAIT:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1071
      // Do nothing
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1072
      break;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1073
    case CLOSED:
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1074
      // Send RST if the incoming packet is not a RST
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1075
      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
  1076
        { // 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
  1077
          TcpHeader h;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1078
          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
  1079
          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
  1080
          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
  1081
          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
  1082
          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
  1083
          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
  1084
          AddOptions (h);
11508
e50a1cb4d7db DoForwardUp behavior unified for IPv4 and IPv6
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11507
diff changeset
  1085
          m_tcp->SendPacket (Create<Packet> (), h, toAddress, fromAddress, m_boundnetdevice);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1086
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1087
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1088
    case SYN_SENT:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1089
      ProcessSynSent (packet, tcpHeader);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1090
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1091
    case SYN_RCVD:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1092
      ProcessSynRcvd (packet, tcpHeader, fromAddress, toAddress);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1093
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1094
    case FIN_WAIT_1:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1095
    case FIN_WAIT_2:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1096
    case CLOSE_WAIT:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1097
      ProcessWait (packet, tcpHeader);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1098
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1099
    case CLOSING:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1100
      ProcessClosing (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 LAST_ACK:
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1103
      ProcessLastAck (packet, tcpHeader);
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
    default: // mute compiler
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1106
      break;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1107
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1108
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1109
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1110
/* 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
  1111
    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
  1112
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1113
TcpSocketBase::ProcessEstablished (Ptr<Packet> packet, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1114
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1115
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1116
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1117
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1118
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1119
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1120
  // Different flags are different events
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1121
  if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1122
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1123
      ReceivedAck (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1124
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1125
  else if (tcpflags == TcpHeader::SYN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1126
    { // 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
  1127
      // 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
  1128
      // RFC793. Thus this is ignored.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1129
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1130
  else if (tcpflags == (TcpHeader::SYN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1131
    { // 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
  1132
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1133
  else if (tcpflags == TcpHeader::FIN || tcpflags == (TcpHeader::FIN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1134
    { // Received FIN or FIN+ACK, bring down this socket nicely
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1135
      PeerClose (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1136
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1137
  else if (tcpflags == 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1138
    { // No flags means there is only data
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1139
      ReceivedData (packet, tcpHeader);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1140
      if (m_rxBuffer->Finished ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1141
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1142
          PeerClose (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1143
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1144
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1145
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1146
    { // 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
  1147
      if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1148
        { // this must be an invalid flag, send reset
11510
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1149
          NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) << " received. Reset packet is sent.");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1150
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1151
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1152
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1153
    }
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1156
/* Process the newly received ACK */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1157
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1158
TcpSocketBase::ReceivedAck (Ptr<Packet> packet, const TcpHeader& 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
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1161
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1162
  // Received ACK. Compare the ACK number against highest unacked seqno
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1163
  if (0 == (tcpHeader.GetFlags () & TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1164
    { // Ignore if no ACK flag
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1165
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1166
  else if (tcpHeader.GetAckNumber () < m_txBuffer->HeadSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1167
    { // Case 1: Old ACK, ignored.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1168
      NS_LOG_LOGIC ("Ignored ack of " << tcpHeader.GetAckNumber ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1169
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1170
  else if (tcpHeader.GetAckNumber () == m_txBuffer->HeadSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1171
    { // Case 2: Potentially a duplicated ACK
9078
11ac313c0610 bug 1506 dup ack piggyback fix
Brian Swenson <bswenson3@gatech.edu>
parents: 9020
diff changeset
  1172
      if (tcpHeader.GetAckNumber () < m_nextTxSequence && packet->GetSize() == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1173
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1174
          NS_LOG_LOGIC ("Dupack of " << tcpHeader.GetAckNumber ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1175
          DupAck (tcpHeader, ++m_dupAckCount);
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
      // otherwise, the ACK is precisely equal to the nextTxSequence
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1178
      NS_ASSERT (tcpHeader.GetAckNumber () <= m_nextTxSequence);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1179
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1180
  else if (tcpHeader.GetAckNumber () > m_txBuffer->HeadSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1181
    { // Case 3: New ACK, reset m_dupAckCount and update m_txBuffer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1182
      NS_LOG_LOGIC ("New ack of " << tcpHeader.GetAckNumber ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1183
      NewAck (tcpHeader.GetAckNumber ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1184
      m_dupAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1185
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1186
  // If there is any data piggybacked, store it into m_rxBuffer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1187
  if (packet->GetSize () > 0)
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
      ReceivedData (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1190
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1191
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1192
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1193
/* Received a packet upon LISTEN state. */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1194
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1195
TcpSocketBase::ProcessListen (Ptr<Packet> packet, const TcpHeader& tcpHeader,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1196
                              const Address& fromAddress, const Address& toAddress)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1197
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1198
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1199
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1200
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1201
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1202
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1203
  // Fork a socket if received a SYN. Do nothing otherwise.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1204
  // 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
  1205
  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
  1206
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1207
      return;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1208
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1209
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1210
  // 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
  1211
  // 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
  1212
  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
  1213
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1214
      return;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1215
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1216
  // Clone the socket, simulate fork
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1217
  Ptr<TcpSocketBase> newSock = Fork ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1218
  NS_LOG_LOGIC ("Cloned a TcpSocketBase " << newSock);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1219
  Simulator::ScheduleNow (&TcpSocketBase::CompleteFork, newSock,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1220
                          packet, tcpHeader, fromAddress, toAddress);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1221
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1222
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1223
/* Received a packet upon SYN_SENT */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1224
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1225
TcpSocketBase::ProcessSynSent (Ptr<Packet> packet, const TcpHeader& tcpHeader)
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
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1228
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1229
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1230
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1231
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1232
  if (tcpflags == 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1233
    { // 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
  1234
      NS_LOG_INFO ("SYN_SENT -> ESTABLISHED");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1235
      m_state = ESTABLISHED;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1236
      m_connected = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1237
      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
  1238
      m_delAckCount = m_delAckMaxCount;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1239
      ReceivedData (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1240
      Simulator::ScheduleNow (&TcpSocketBase::ConnectionSucceeded, this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1241
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1242
  else if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1243
    { // Ignore ACK in SYN_SENT
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
  else if (tcpflags == TcpHeader::SYN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1246
    { // 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
  1247
      NS_LOG_INFO ("SYN_SENT -> SYN_RCVD");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1248
      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
  1249
      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
  1250
      m_rxBuffer->SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1251
      SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1252
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1253
  else if (tcpflags == (TcpHeader::SYN | TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1254
           && m_nextTxSequence + SequenceNumber32 (1) == tcpHeader.GetAckNumber ())
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1255
    { // Handshake completed
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1256
      NS_LOG_INFO ("SYN_SENT -> ESTABLISHED");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1257
      m_state = ESTABLISHED;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1258
      m_connected = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1259
      m_retxEvent.Cancel ();
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1260
      m_rxBuffer->SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1261
      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
  1262
      m_txBuffer->SetHeadSequence (m_nextTxSequence);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1263
      SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1264
      SendPendingData (m_connected);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1265
      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
  1266
      // 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
  1267
      // 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
  1268
      m_delAckCount = m_delAckMaxCount;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1269
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1270
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1271
    { // Other in-sequence input
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1272
      if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1273
        { // When (1) rx of FIN+ACK; (2) rx of FIN; (3) rx of bad flags
11510
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1274
          NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) <<
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1275
                        " received. Reset packet is sent.");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1276
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1277
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1278
      CloseAndNotify ();
6694
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
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1281
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1282
/* Received a packet upon SYN_RCVD */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1283
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1284
TcpSocketBase::ProcessSynRcvd (Ptr<Packet> packet, const TcpHeader& tcpHeader,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1285
                               const Address& fromAddress, const Address& toAddress)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1286
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1287
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1288
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1289
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1290
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1291
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1292
  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
  1293
      || (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
  1294
          && m_nextTxSequence + SequenceNumber32 (1) == tcpHeader.GetAckNumber ()))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1295
    { // 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
  1296
      // 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
  1297
      // handshake is completed nicely.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1298
      NS_LOG_INFO ("SYN_RCVD -> ESTABLISHED");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1299
      m_state = ESTABLISHED;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1300
      m_connected = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1301
      m_retxEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1302
      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
  1303
      m_txBuffer->SetHeadSequence (m_nextTxSequence);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1304
      if (m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1305
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1306
          m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1307
                               InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1308
        }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1309
      else if (m_endPoint6)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1310
        {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1311
          m_endPoint6->SetPeer (Inet6SocketAddress::ConvertFrom (fromAddress).GetIpv6 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1312
                                Inet6SocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1313
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1314
      // Always respond to first data packet to speed up the connection.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1315
      // Remove to get the behaviour of old NS-3 code.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1316
      m_delAckCount = m_delAckMaxCount;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1317
      ReceivedAck (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1318
      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
  1319
      // 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
  1320
      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
  1321
        {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1322
          NotifySend (GetTxAvailable ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1323
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1324
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1325
  else if (tcpflags == TcpHeader::SYN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1326
    { // 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
  1327
      m_rxBuffer->SetNextRxSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (1));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1328
      SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1329
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1330
  else if (tcpflags == (TcpHeader::FIN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1331
    {
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1332
      if (tcpHeader.GetSequenceNumber () == m_rxBuffer->NextRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1333
        { // In-sequence FIN before connection complete. Set up connection and close.
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
          PeerClose (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1349
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1350
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1351
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1352
    { // Other in-sequence input
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1353
      if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1354
        { // When (1) rx of SYN+ACK; (2) rx of FIN; (3) rx of bad flags
11510
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1355
          NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) <<
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1356
                        " received. Reset packet is sent.");
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1357
          if (m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1358
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1359
              m_endPoint->SetPeer (InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1360
                                   InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1361
            }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1362
          else if (m_endPoint6)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1363
            {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1364
              m_endPoint6->SetPeer (Inet6SocketAddress::ConvertFrom (fromAddress).GetIpv6 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1365
                                    Inet6SocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1366
            }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1367
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1368
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1369
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1370
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1371
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1372
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1373
/* 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
  1374
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1375
TcpSocketBase::ProcessWait (Ptr<Packet> packet, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1376
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1377
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1378
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1379
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1380
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1381
9020
200c9dd61e1a bug 1256: Unnecessary SND.NXT advance, missing ACK for Out of Order segments
Tom Henderson <tomh@tomh.org>
parents: 7790
diff changeset
  1382
  if (packet->GetSize () > 0 && tcpflags != TcpHeader::ACK)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1383
    { // Bare data, accept it
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1384
      ReceivedData (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1385
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1386
  else if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1387
    { // 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
  1388
      ReceivedAck (packet, tcpHeader);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1389
      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
  1390
          && tcpHeader.GetAckNumber () == m_highTxMark + SequenceNumber32 (1))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1391
        { // This ACK corresponds to the FIN sent
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1392
          NS_LOG_INFO ("FIN_WAIT_1 -> FIN_WAIT_2");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1393
          m_state = FIN_WAIT_2;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1394
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1395
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1396
  else if (tcpflags == TcpHeader::FIN || tcpflags == (TcpHeader::FIN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1397
    { // Got FIN, respond with ACK and move to next state
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1398
      if (tcpflags & TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1399
        { // Process the ACK first
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1400
          ReceivedAck (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1401
        }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1402
      m_rxBuffer->SetFinSequence (tcpHeader.GetSequenceNumber ());
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
  else if (tcpflags == TcpHeader::SYN || tcpflags == (TcpHeader::SYN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1405
    { // Duplicated SYN or SYN+ACK, possibly due to spurious retransmission
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1406
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1407
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1408
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1409
    { // This is a RST or bad flags
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1410
      if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1411
        {
11510
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1412
          NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) <<
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1413
                        " received. Reset packet is sent.");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1414
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1415
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1416
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1417
      return;
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
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1420
  // 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
  1421
  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
  1422
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1423
      if (m_state == FIN_WAIT_1)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1424
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1425
          NS_LOG_INFO ("FIN_WAIT_1 -> CLOSING");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1426
          m_state = CLOSING;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1427
          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
  1428
              && tcpHeader.GetAckNumber () == m_highTxMark + SequenceNumber32 (1))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1429
            { // 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
  1430
              TimeWait ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1431
            }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1432
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1433
      else if (m_state == FIN_WAIT_2)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1434
        {
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1435
          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
  1436
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1437
      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
  1438
      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
  1439
        {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1440
          NotifyDataRecv ();
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  1441
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1442
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1443
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1444
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1445
/* Received a packet upon CLOSING */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1446
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1447
TcpSocketBase::ProcessClosing (Ptr<Packet> packet, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1448
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1449
  NS_LOG_FUNCTION (this << tcpHeader);
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
  // Extract the flags. PSH and URG are not honoured.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1452
  uint8_t tcpflags = tcpHeader.GetFlags () & ~(TcpHeader::PSH | TcpHeader::URG);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1453
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1454
  if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1455
    {
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1456
      if (tcpHeader.GetSequenceNumber () == m_rxBuffer->NextRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1457
        { // 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
  1458
          TimeWait ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1459
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1460
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1461
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1462
    { // 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
  1463
      // 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
  1464
      if (tcpflags == TcpHeader::FIN || tcpflags == (TcpHeader::FIN | TcpHeader::ACK))
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1465
        { // FIN from the peer as well. We can close immediately.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1466
          SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1467
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1468
      else if (tcpflags != TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1469
        { // Receive of SYN or SYN+ACK or bad flags or pure data
11510
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1470
          NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) << " received. Reset packet is sent.");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1471
          SendRST ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1472
        }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1473
      CloseAndNotify ();
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 LAST_ACK */
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::ProcessLastAck (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 == 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1487
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1488
      ReceivedData (packet, tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1489
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1490
  else if (tcpflags == TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1491
    {
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1492
      if (tcpHeader.GetSequenceNumber () == m_rxBuffer->NextRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1493
        { // This ACK corresponds to the FIN sent. This socket closed peacefully.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1494
          CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1495
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1496
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1497
  else if (tcpflags == TcpHeader::FIN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1498
    { // Received FIN again, the peer probably lost the FIN+ACK
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1499
      SendEmptyPacket (TcpHeader::FIN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1500
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1501
  else if (tcpflags == (TcpHeader::FIN | TcpHeader::ACK) || tcpflags == TcpHeader::RST)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1502
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1503
      CloseAndNotify ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1504
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1505
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1506
    { // Received a SYN or SYN+ACK or bad flags
11510
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1507
      NS_LOG_LOGIC ("Illegal flag " << TcpHeader::FlagsToString (tcpflags) << " received. Reset packet is sent.");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1508
      SendRST ();
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1509
      CloseAndNotify ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1510
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1511
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1512
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1513
/* 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
  1514
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1515
TcpSocketBase::PeerClose (Ptr<Packet> p, const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1516
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1517
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1518
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1519
  // 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
  1520
  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
  1521
      || tcpHeader.GetSequenceNumber () > m_rxBuffer->MaxRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1522
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1523
      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
  1524
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1525
  // 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
  1526
  m_rxBuffer->SetFinSequence (tcpHeader.GetSequenceNumber () + SequenceNumber32 (p->GetSize ()));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1527
  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
  1528
  // If there is any piggybacked data, process it
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1529
  if (p->GetSize ())
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1530
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1531
      ReceivedData (p, tcpHeader);
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
  // 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
  1534
  if (!m_rxBuffer->Finished ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1535
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1536
      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
  1537
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1538
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1539
  // 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
  1540
  if (m_state == FIN_WAIT_1)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1541
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1542
      NS_LOG_INFO ("FIN_WAIT_1 -> CLOSING");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1543
      m_state = CLOSING;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1544
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1545
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1546
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1547
  DoPeerClose (); // Change state, respond with ACK
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1550
/* Received a in-sequence FIN. Close down this socket. */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1551
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1552
TcpSocketBase::DoPeerClose (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1553
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1554
  NS_ASSERT (m_state == ESTABLISHED || m_state == SYN_RCVD);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1555
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1556
  // Move the state to CLOSE_WAIT
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1557
  NS_LOG_INFO (TcpStateName[m_state] << " -> CLOSE_WAIT");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1558
  m_state = CLOSE_WAIT;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1559
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1560
  if (!m_closeNotified)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1561
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1562
      // 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
  1563
      // 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
  1564
      // 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
  1565
      // 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
  1566
      // 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
  1567
      // explicitly.
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1568
      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
  1569
      NotifyNormalClose ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1570
      m_closeNotified = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1571
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1572
  if (m_shutdownSend)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1573
    { // 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
  1574
      Close ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1575
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1576
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1577
    { // Need to ack, the application will close later
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1578
      SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1579
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1580
  if (m_state == LAST_ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1581
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1582
      NS_LOG_LOGIC ("TcpSocketBase " << this << " scheduling LATO1");
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1583
      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
  1584
      m_lastAckEvent = Simulator::Schedule (lastRto, &TcpSocketBase::LastAckTimeout, this);
6694
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
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1587
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1588
/* 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
  1589
   SetupCallback(), invoked when the endpoint is destroyed. */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1590
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1591
TcpSocketBase::Destroy (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1592
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1593
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1594
  m_endPoint = 0;
7747
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1595
  if (m_tcp != 0)
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1596
    {
11500
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
  1597
      m_tcp->RemoveSocket(this);
7747
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1598
    }
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1599
  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
  1600
                (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1601
  CancelAllTimers ();
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1602
}
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1603
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1604
/* 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
  1605
   SetupCallback(), invoked when the endpoint is destroyed. */
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1606
void
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1607
TcpSocketBase::Destroy6 (void)
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1608
{
53a26ce38807 Bug 1377: various memory leaks
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 7717
diff changeset
  1609
  NS_LOG_FUNCTION (this);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1610
  m_endPoint6 = 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1611
  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
  1612
    {
11500
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
  1613
      m_tcp->RemoveSocket(this);
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1614
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1615
  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
  1616
                (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1617
  CancelAllTimers ();
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
/* Send an empty packet with specified TCP flags */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1621
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1622
TcpSocketBase::SendEmptyPacket (uint8_t flags)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1623
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1624
  NS_LOG_FUNCTION (this << (uint32_t)flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1625
  Ptr<Packet> p = Create<Packet> ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1626
  TcpHeader header;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1627
  SequenceNumber32 s = m_nextTxSequence;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1628
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1629
  /*
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1630
   * Add tags for each socket option.
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1631
   * 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
  1632
   * 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
  1633
   * the corresponding tags will be read.
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1634
   */
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1635
  if (IsManualIpTos ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1636
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1637
      SocketIpTosTag ipTosTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1638
      ipTosTag.SetTos (GetIpTos ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1639
      p->AddPacketTag (ipTosTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1640
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1641
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1642
  if (IsManualIpv6Tclass ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1643
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1644
      SocketIpv6TclassTag ipTclassTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1645
      ipTclassTag.SetTclass (GetIpv6Tclass ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1646
      p->AddPacketTag (ipTclassTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1647
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1648
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1649
  if (IsManualIpTtl ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1650
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1651
      SocketIpTtlTag ipTtlTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1652
      ipTtlTag.SetTtl (GetIpTtl ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1653
      p->AddPacketTag (ipTtlTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1654
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1655
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1656
  if (IsManualIpv6HopLimit ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1657
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1658
      SocketIpv6HopLimitTag ipHopLimitTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1659
      ipHopLimitTag.SetHopLimit (GetIpv6HopLimit ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1660
      p->AddPacketTag (ipHopLimitTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1661
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1662
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1663
  if (m_endPoint == 0 && m_endPoint6 == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1664
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1665
      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
  1666
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1667
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1668
  if (flags & TcpHeader::FIN)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1669
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1670
      flags |= TcpHeader::ACK;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1671
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1672
  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
  1673
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1674
      ++s;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1675
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1676
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1677
  header.SetFlags (flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1678
  header.SetSequenceNumber (s);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1679
  header.SetAckNumber (m_rxBuffer->NextRxSequence ());
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1680
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1681
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1682
      header.SetSourcePort (m_endPoint->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1683
      header.SetDestinationPort (m_endPoint->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1684
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1685
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1686
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1687
      header.SetSourcePort (m_endPoint6->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1688
      header.SetDestinationPort (m_endPoint6->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1689
    }
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
  1690
  AddOptions (header);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1691
  header.SetWindowSize (AdvertisedWindowSize ());
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1692
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1693
  // 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
  1694
  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
  1695
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1696
  bool hasSyn = flags & TcpHeader::SYN;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1697
  bool hasFin = flags & TcpHeader::FIN;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1698
  bool isAck = flags == TcpHeader::ACK;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1699
  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
  1700
    {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1701
      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
  1702
        { // 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
  1703
          NS_LOG_LOGIC ("Connection failed.");
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1704
          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
  1705
          CloseAndNotify ();
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1706
          return;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1707
        }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1708
      else
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1709
        { // 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
  1710
          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
  1711
          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
  1712
          m_cnCount--;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1713
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1714
    }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1715
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1716
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1717
      m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1718
                         m_endPoint->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1719
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1720
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1721
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1722
      m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1723
                         m_endPoint6->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1724
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1725
  if (flags & TcpHeader::ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1726
    { // If sending an ACK, cancel the delay ACK as well
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1727
      m_delAckEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1728
      m_delAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1729
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1730
  if (m_retxEvent.IsExpired () && (hasSyn || hasFin) && !isAck )
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1731
    { // Retransmit SYN / SYN+ACK / FIN / FIN+ACK to guard against lost
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1732
      NS_LOG_LOGIC ("Schedule retransmission timeout at time "
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1733
                    << Simulator::Now ().GetSeconds () << " to expire at time "
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1734
                    << (Simulator::Now () + m_rto.Get ()).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1735
      m_retxEvent = Simulator::Schedule (m_rto, &TcpSocketBase::SendEmptyPacket, this, flags);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1736
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1737
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1738
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1739
/* 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
  1740
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1741
TcpSocketBase::SendRST (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1742
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1743
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1744
  SendEmptyPacket (TcpHeader::RST);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1745
  NotifyErrorClose ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1746
  DeallocateEndPoint ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1747
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1748
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1749
/* Deallocate the end point and cancel all the timers */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1750
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1751
TcpSocketBase::DeallocateEndPoint (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1752
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1753
  if (m_endPoint != 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1754
    {
11044
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
  1755
      CancelAllTimers ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1756
      m_endPoint->SetDestroyCallback (MakeNullCallback<void> ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1757
      m_tcp->DeAllocate (m_endPoint);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1758
      m_endPoint = 0;
11500
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
  1759
      m_tcp->RemoveSocket(this);
11044
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
  1760
    }
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
  1761
  else if (m_endPoint6 != 0)
6b153691af7c bug 1791: improve TCP endpoint deallocation code
Pedro Silva <pmms@inesctec.pt>
parents: 11040
diff changeset
  1762
    {
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1763
      CancelAllTimers ();
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1764
      m_endPoint6->SetDestroyCallback (MakeNullCallback<void> ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1765
      m_tcp->DeAllocate (m_endPoint6);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1766
      m_endPoint6 = 0;
11500
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
  1767
      m_tcp->RemoveSocket(this);
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1768
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1769
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1770
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1771
/* 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
  1772
int
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1773
TcpSocketBase::SetupEndpoint ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1774
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1775
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1776
  Ptr<Ipv4> ipv4 = m_node->GetObject<Ipv4> ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1777
  NS_ASSERT (ipv4 != 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1778
  if (ipv4->GetRoutingProtocol () == 0)
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
      NS_FATAL_ERROR ("No Ipv4RoutingProtocol in the node");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1781
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1782
  // 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
  1783
  // interface's address
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1784
  Ipv4Header header;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1785
  header.SetDestination (m_endPoint->GetPeerAddress ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1786
  Socket::SocketErrno errno_;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1787
  Ptr<Ipv4Route> route;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1788
  Ptr<NetDevice> oif = m_boundnetdevice;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1789
  route = ipv4->GetRoutingProtocol ()->RouteOutput (Ptr<Packet> (), header, oif, errno_);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1790
  if (route == 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1791
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1792
      NS_LOG_LOGIC ("Route to " << m_endPoint->GetPeerAddress () << " does not exist");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1793
      NS_LOG_ERROR (errno_);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1794
      m_errno = errno_;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1795
      return -1;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1796
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1797
  NS_LOG_LOGIC ("Route exists");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1798
  m_endPoint->SetLocalAddress (route->GetSource ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1799
  return 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1800
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1801
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1802
int
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1803
TcpSocketBase::SetupEndpoint6 ()
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1804
{
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1805
  NS_LOG_FUNCTION (this);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1806
  Ptr<Ipv6L3Protocol> ipv6 = m_node->GetObject<Ipv6L3Protocol> ();
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1807
  NS_ASSERT (ipv6 != 0);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1808
  if (ipv6->GetRoutingProtocol () == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1809
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1810
      NS_FATAL_ERROR ("No Ipv6RoutingProtocol in the node");
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1811
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1812
  // 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
  1813
  // interface's address
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1814
  Ipv6Header header;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1815
  header.SetDestinationAddress (m_endPoint6->GetPeerAddress ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1816
  Socket::SocketErrno errno_;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1817
  Ptr<Ipv6Route> route;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1818
  Ptr<NetDevice> oif = m_boundnetdevice;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1819
  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
  1820
  if (route == 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1821
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1822
      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
  1823
      NS_LOG_ERROR (errno_);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1824
      m_errno = errno_;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1825
      return -1;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1826
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1827
  NS_LOG_LOGIC ("Route exists");
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1828
  m_endPoint6->SetLocalAddress (route->GetSource ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1829
  return 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1830
}
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1831
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1832
/* 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
  1833
   TcpSocketBase cloned, allocate a new end point to handle the incoming
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1834
   connection and send a SYN+ACK to complete the handshake. */
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1835
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1836
TcpSocketBase::CompleteFork (Ptr<Packet> p, const TcpHeader& h,
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1837
                             const Address& fromAddress, const Address& toAddress)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1838
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1839
  // 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
  1840
  if (InetSocketAddress::IsMatchingType (toAddress))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1841
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1842
      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
  1843
                                    InetSocketAddress::ConvertFrom (toAddress).GetPort (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1844
                                    InetSocketAddress::ConvertFrom (fromAddress).GetIpv4 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1845
                                    InetSocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1846
      m_endPoint6 = 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1847
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1848
  else if (Inet6SocketAddress::IsMatchingType (toAddress))
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1849
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1850
      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
  1851
                                      Inet6SocketAddress::ConvertFrom (toAddress).GetPort (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1852
                                      Inet6SocketAddress::ConvertFrom (fromAddress).GetIpv6 (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1853
                                      Inet6SocketAddress::ConvertFrom (fromAddress).GetPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1854
      m_endPoint = 0;
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1855
    }
11500
366c7284d4a8 Thanks to previous commits, now TcpSocketBases uses only public methods on TcpL4Protocol and the friend relation could be removed.
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11362
diff changeset
  1856
  m_tcp->AddSocket(this);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1857
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1858
  // Change the cloned socket from LISTEN state to SYN_RCVD
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1859
  NS_LOG_INFO ("LISTEN -> SYN_RCVD");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1860
  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
  1861
  m_cnCount = m_cnRetries;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1862
  SetupCallback ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1863
  // 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
  1864
  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
  1865
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1866
  SendEmptyPacket (TcpHeader::SYN | TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1867
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1868
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1869
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1870
TcpSocketBase::ConnectionSucceeded ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1871
{ // Wrapper to protected function NotifyConnectionSucceeded() so that it can
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1872
  // be called as a scheduled event
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1873
  NotifyConnectionSucceeded ();
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1874
  // 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
  1875
  // 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
  1876
  // 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
  1877
  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
  1878
    {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1879
      NotifySend (GetTxAvailable ());
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1880
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1881
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  1882
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  1883
/* 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
  1884
    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
  1885
uint32_t
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1886
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
  1887
{
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1888
  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
  1889
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1890
  bool isRetransmission = false;
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1891
  if ( seq == m_txBuffer->HeadSequence () )
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1892
    {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1893
      isRetransmission = true;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1894
    }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1895
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1896
  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
  1897
  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
  1898
  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
  1899
  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
  1900
11202
6286a5dc3f64 bug 1734: TcpSocketBase produces spurious delayed ACKs (fix due to Lawrence Stewart)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11195
diff changeset
  1901
  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
  1902
    {
6286a5dc3f64 bug 1734: TcpSocketBase produces spurious delayed ACKs (fix due to Lawrence Stewart)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11195
diff changeset
  1903
      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
  1904
      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
  1905
    }
6286a5dc3f64 bug 1734: TcpSocketBase produces spurious delayed ACKs (fix due to Lawrence Stewart)
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11195
diff changeset
  1906
9145
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1907
  /*
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1908
   * Add tags for each socket option.
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1909
   * 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
  1910
   * 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
  1911
   * the corresponding tags will be read.
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1912
   */
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1913
  if (IsManualIpTos ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1914
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1915
      SocketIpTosTag ipTosTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1916
      ipTosTag.SetTos (GetIpTos ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1917
      p->AddPacketTag (ipTosTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1918
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1919
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1920
  if (IsManualIpv6Tclass ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1921
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1922
      SocketIpv6TclassTag ipTclassTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1923
      ipTclassTag.SetTclass (GetIpv6Tclass ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1924
      p->AddPacketTag (ipTclassTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1925
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1926
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1927
  if (IsManualIpTtl ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1928
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1929
      SocketIpTtlTag ipTtlTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1930
      ipTtlTag.SetTtl (GetIpTtl ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1931
      p->AddPacketTag (ipTtlTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1932
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1933
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1934
  if (IsManualIpv6HopLimit ())
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1935
    {
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1936
      SocketIpv6HopLimitTag ipHopLimitTag;
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1937
      ipHopLimitTag.SetHopLimit (GetIpv6HopLimit ());
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1938
      p->AddPacketTag (ipHopLimitTag);
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1939
    }
5752b425cdf5 Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 9118
diff changeset
  1940
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1941
  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
  1942
    {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1943
      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
  1944
      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
  1945
        { // 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
  1946
          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
  1947
          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
  1948
        }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1949
      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
  1950
        { // 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
  1951
          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
  1952
          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
  1953
        }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1954
    }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1955
  TcpHeader header;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1956
  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
  1957
  header.SetSequenceNumber (seq);
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  1958
  header.SetAckNumber (m_rxBuffer->NextRxSequence ());
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1959
  if (m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1960
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1961
      header.SetSourcePort (m_endPoint->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1962
      header.SetDestinationPort (m_endPoint->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1963
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1964
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1965
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1966
      header.SetSourcePort (m_endPoint6->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1967
      header.SetDestinationPort (m_endPoint6->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1968
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1969
  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
  1970
  AddOptions (header);
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1971
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1972
  if (m_retxEvent.IsExpired () )
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1973
    {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1974
      // RFC 6298, clause 2.5
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1975
      Time doubledRto = m_rto + m_rto;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1976
      m_rto = Min (doubledRto, Time::FromDouble (60,  Time::S));
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1977
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1978
      // Schedules retransmit
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1979
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  1980
      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
  1981
                    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
  1982
                    (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
  1983
      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
  1984
    }
11510
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1985
  NS_LOG_LOGIC ("Send packet via TcpL4Protocol with flags" <<
030e5d6efdd6 TCP flags are now printed using string instead of numbers
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11508
diff changeset
  1986
                TcpHeader::FlagsToString (flags));
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1987
  if (m_endPoint)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1988
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1989
      m_tcp->SendPacket (p, header, m_endPoint->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1990
                         m_endPoint->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1991
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1992
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1993
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1994
      m_tcp->SendPacket (p, header, m_endPoint6->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1995
                         m_endPoint6->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  1996
    }
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1997
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  1998
  // 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
  1999
  if (isRetransmission == false)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2000
    { // 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
  2001
      m_history.push_back (RttHistory (seq, sz, Simulator::Now () ));
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2002
    }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2003
  else
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2004
    { // 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
  2005
      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
  2006
        {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2007
          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
  2008
            { // Found it
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2009
              i->retx = true;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2010
              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
  2011
              break;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2012
            }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2013
        }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2014
    }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2015
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2016
  // 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
  2017
  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
  2018
    {
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2019
      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
  2020
    }
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2021
  // Update highTxMark
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2022
  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
  2023
  return sz;
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2024
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2025
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  2026
/* 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
  2027
 *  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
  2028
 */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2029
bool
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2030
TcpSocketBase::SendPendingData (bool withAck)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2031
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2032
  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
  2033
  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
  2034
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2035
      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
  2036
    }
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2037
  if (m_endPoint == 0 && m_endPoint6 == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2038
    {
6768
805f5fc7f670 remove stale doxygen and comments pertaining to TCP
Tom Henderson <tomh@tomh.org>
parents: 6738
diff changeset
  2039
      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
  2040
      return false; // Is this the right way to handle this condition?
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2041
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2042
  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
  2043
  while (m_txBuffer->SizeFromSequence (m_nextTxSequence))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2044
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2045
      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
  2046
      // 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
  2047
      if (w < m_segmentSize && m_txBuffer->SizeFromSequence (m_nextTxSequence) > w)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2048
        {
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
  2049
          NS_LOG_LOGIC ("Preventing Silly Window Syndrome. Wait to send.");
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2050
          break; // No more
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2051
        }
7619
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2052
      // 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
  2053
      // 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
  2054
      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
  2055
          && 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
  2056
        {
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2057
          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
  2058
          break;
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2059
        }
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
  2060
      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
  2061
                    " 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
  2062
                    " 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
  2063
                    " 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
  2064
                    " 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
  2065
                    " 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
  2066
                    " 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
  2067
                    " pd->SFS " << m_txBuffer->SizeFromSequence (m_nextTxSequence));
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2068
      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
  2069
      uint32_t sz = SendDataPacket (m_nextTxSequence, s, withAck);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2070
      nPacketsSent++;                             // Count sent this loop
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2071
      m_nextTxSequence += sz;                     // Advance next tx sequence
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2072
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2073
  NS_LOG_LOGIC ("SendPendingData sent " << nPacketsSent << " packets");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2074
  return (nPacketsSent > 0);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2075
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2076
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2077
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2078
TcpSocketBase::UnAckDataCount ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2079
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2080
  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
  2081
  return m_nextTxSequence.Get () - m_txBuffer->HeadSequence ();
6694
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
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2084
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2085
TcpSocketBase::BytesInFlight ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2086
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2087
  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
  2088
  return m_highTxMark.Get () - m_txBuffer->HeadSequence ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2089
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2090
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2091
uint32_t
11513
99af6df16387 Window() is now managed inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11512
diff changeset
  2092
TcpSocketBase::Window (void)
99af6df16387 Window() is now managed inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11512
diff changeset
  2093
{
99af6df16387 Window() is now managed inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11512
diff changeset
  2094
  NS_LOG_FUNCTION (this);
99af6df16387 Window() is now managed inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11512
diff changeset
  2095
  return std::min (m_rWnd.Get (), m_cWnd.Get ());
99af6df16387 Window() is now managed inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11512
diff changeset
  2096
}
99af6df16387 Window() is now managed inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11512
diff changeset
  2097
99af6df16387 Window() is now managed inside TcpSocketBase
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11512
diff changeset
  2098
uint32_t
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2099
TcpSocketBase::AvailableWindow ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2100
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2101
  NS_LOG_FUNCTION_NOARGS ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2102
  uint32_t unack = UnAckDataCount (); // Number of outstanding bytes
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2103
  uint32_t win = Window (); // Number of bytes allowed to be outstanding
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2104
  NS_LOG_LOGIC ("UnAckCount=" << unack << ", Win=" << win);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2105
  return (win < unack) ? 0 : (win - unack);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2106
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2107
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2108
uint16_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2109
TcpSocketBase::AdvertisedWindowSize ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2110
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2111
  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
  2112
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
  2113
  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
  2114
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
  2115
  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
  2116
    {
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
  2117
      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
  2118
      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
  2119
    }
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
  2120
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
  2121
  return (uint16_t) w;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2122
}
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
// Receipt of new packet, put into Rx buffer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2125
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2126
TcpSocketBase::ReceivedData (Ptr<Packet> p, const TcpHeader& tcpHeader)
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
  NS_LOG_FUNCTION (this << tcpHeader);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2129
  NS_LOG_LOGIC ("seq " << tcpHeader.GetSequenceNumber () <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2130
                " ack " << tcpHeader.GetAckNumber () <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2131
                " pkt size " << p->GetSize () );
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2132
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2133
  // 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
  2134
  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
  2135
  if (!m_rxBuffer->Add (p, tcpHeader))
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2136
    { // Insert failed: No data or RX buffer full
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2137
      SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2138
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2139
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2140
  // 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
  2141
  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
  2142
    { // 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
  2143
      SendEmptyPacket (TcpHeader::ACK);
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
  else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2146
    { // In-sequence packet: ACK if delayed ack count allows
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2147
      if (++m_delAckCount >= m_delAckMaxCount)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2148
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2149
          m_delAckEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2150
          m_delAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2151
          SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2152
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2153
      else if (m_delAckEvent.IsExpired ())
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2154
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2155
          m_delAckEvent = Simulator::Schedule (m_delAckTimeout,
7176
9f2663992e99 internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 7045
diff changeset
  2156
                                               &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
  2157
          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
  2158
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2159
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2160
  // 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
  2161
  if (expectedSeq < m_rxBuffer->NextRxSequence ())
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2162
    { // 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
  2163
      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
  2164
        {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2165
          NotifyDataRecv ();
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2166
        }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2167
      // Handle exceptions
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2168
      if (m_closeNotified)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2169
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2170
          NS_LOG_WARN ("Why TCP " << this << " got data after close notification?");
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
      // 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
  2173
      // 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
  2174
      if (m_rxBuffer->Finished () && (tcpHeader.GetFlags () & TcpHeader::FIN) == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2175
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2176
          DoPeerClose ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2177
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2178
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2179
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2180
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
  2181
/**
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
  2182
 * \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
  2183
 *
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
  2184
 * 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
  2185
 *
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
  2186
 * \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
  2187
 */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2188
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2189
TcpSocketBase::EstimateRtt (const TcpHeader& tcpHeader)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2190
{
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2191
  SequenceNumber32 ackSeq = tcpHeader.GetAckNumber();
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2192
  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
  2193
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2194
  // 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
  2195
  // 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
  2196
  // 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
  2197
  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
  2198
    {
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2199
      RttHistory& h = m_history.front ();
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2200
      if (!h.retx && ackSeq >= (h.seq + SequenceNumber32 (h.count)))
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2201
        { // Ok to use this sample
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2202
          if (m_timestampEnabled && tcpHeader.HasOption (TcpOption::TS))
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2203
            {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2204
              Ptr<TcpOptionTS> ts;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2205
              ts = DynamicCast<TcpOptionTS> (tcpHeader.GetOption (TcpOption::TS));
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2206
              m = TcpOptionTS::ElapsedTimeFromTsValue (ts->GetEcho ());
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2207
            }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2208
          else
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2209
            {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2210
              m = Simulator::Now () - h.time; // Elapsed time
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2211
            }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2212
        }
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
  2213
    }
9118
5991df10eb5e bug 1509 RTTEstimator invalid values fix
Brian Swenson <bswenson3@gatech.edu>
parents: 9095
diff changeset
  2214
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2215
  // Now delete all ack history with seq <= ack
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2216
  while(!m_history.empty ())
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2217
    {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2218
      RttHistory& h = m_history.front ();
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2219
      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
  2220
      m_history.pop_front (); // Remove
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2221
    }
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2222
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2223
  if (!m.IsZero ())
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2224
    {
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2225
      m_rtt->Measurement (m);                // Log the measurement
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2226
      // 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
  2227
      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
  2228
      m_lastRtt = m_rtt->GetEstimate ();
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2229
      NS_LOG_FUNCTION(this << m_lastRtt);
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2230
    }
7790
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2231
}
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2232
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2233
// Called by the ReceivedAck() when new ACK received and by ProcessSynRcvd()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2234
// when the three-way handshake completed. This cancels retransmission timer
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2235
// and advances Tx window
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2236
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2237
TcpSocketBase::NewAck (SequenceNumber32 const& ack)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2238
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2239
  NS_LOG_FUNCTION (this << ack);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2240
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2241
  if (m_state != SYN_RCVD)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2242
    { // Set RTO unless the ACK is received in SYN_RCVD state
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2243
      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
  2244
                    (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2245
      m_retxEvent.Cancel ();
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2246
      // 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
  2247
      // 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
  2248
      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
  2249
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2250
      NS_LOG_LOGIC (this << " Schedule ReTxTimeout at time " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2251
                    Simulator::Now ().GetSeconds () << " to expire at time " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2252
                    (Simulator::Now () + m_rto.Get ()).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2253
      m_retxEvent = Simulator::Schedule (m_rto, &TcpSocketBase::ReTxTimeout, this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2254
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2255
  if (m_rWnd.Get () == 0 && m_persistEvent.IsExpired ())
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2256
    { // Zero window: Enter persist state to send 1 byte to probe
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2257
      NS_LOG_LOGIC (this << "Enter zerowindow persist state");
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2258
      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
  2259
                    (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2260
      m_retxEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2261
      NS_LOG_LOGIC ("Schedule persist timeout at time " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2262
                    Simulator::Now ().GetSeconds () << " to expire at time " <<
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2263
                    (Simulator::Now () + m_persistTimeout).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2264
      m_persistEvent = Simulator::Schedule (m_persistTimeout, &TcpSocketBase::PersistTimeout, this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2265
      NS_ASSERT (m_persistTimeout == Simulator::GetDelayLeft (m_persistEvent));
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2266
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2267
  // Note the highest ACK and tell app to send more
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2268
  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
  2269
                " 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
  2270
  m_txBuffer->DiscardUpTo (ack);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2271
  if (GetTxAvailable () > 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2272
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2273
      NotifySend (GetTxAvailable ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2274
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2275
  if (ack > m_nextTxSequence)
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
      m_nextTxSequence = ack; // If advanced
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2278
    }
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2279
  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
  2280
    { // No retransmit timer if no data to retransmit
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2281
      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
  2282
                    (Simulator::Now () + Simulator::GetDelayLeft (m_retxEvent)).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2283
      m_retxEvent.Cancel ();
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
  // 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
  2286
  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
  2287
    {
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
  2288
      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
  2289
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2290
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2291
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2292
// Retransmit timeout
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2293
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2294
TcpSocketBase::ReTxTimeout ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2295
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2296
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2297
  NS_LOG_LOGIC (this << " ReTxTimeout Expired at time " << Simulator::Now ().GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2298
  // 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
  2299
  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
  2300
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2301
      return;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2302
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2303
  // 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
  2304
  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
  2305
    {
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2306
      return;
47d6d575412c Bug 1362 - ICMPv6 does not forward ICMPs to upper layers
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7747
diff changeset
  2307
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2308
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2309
  Retransmit ();
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
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2312
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2313
TcpSocketBase::DelAckTimeout (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2314
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2315
  m_delAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2316
  SendEmptyPacket (TcpHeader::ACK);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2317
}
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
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2320
TcpSocketBase::LastAckTimeout (void)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2321
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2322
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2323
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2324
  m_lastAckEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2325
  if (m_state == LAST_ACK)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2326
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2327
      CloseAndNotify ();
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
  if (!m_closeNotified)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2330
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2331
      m_closeNotified = true;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2332
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2333
}
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
// 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
  2336
// the local knowledge tells that the receiver has zero window size
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2337
// C.f.: RFC793 p.42, RFC1112 sec.4.2.2.17
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2338
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2339
TcpSocketBase::PersistTimeout ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2340
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2341
  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
  2342
  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
  2343
  Ptr<Packet> p = m_txBuffer->CopyFromSequence (1, m_nextTxSequence);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2344
  TcpHeader tcpHeader;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2345
  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
  2346
  tcpHeader.SetAckNumber (m_rxBuffer->NextRxSequence ());
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2347
  tcpHeader.SetWindowSize (AdvertisedWindowSize ());
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2348
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2349
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2350
      tcpHeader.SetSourcePort (m_endPoint->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2351
      tcpHeader.SetDestinationPort (m_endPoint->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2352
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2353
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2354
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2355
      tcpHeader.SetSourcePort (m_endPoint6->GetLocalPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2356
      tcpHeader.SetDestinationPort (m_endPoint6->GetPeerPort ());
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2357
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2358
  AddOptions (tcpHeader);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2359
7717
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2360
  if (m_endPoint != 0)
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2361
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2362
      m_tcp->SendPacket (p, tcpHeader, m_endPoint->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2363
                         m_endPoint->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2364
    }
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2365
  else
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2366
    {
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2367
      m_tcp->SendPacket (p, tcpHeader, m_endPoint6->GetLocalAddress (),
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2368
                         m_endPoint6->GetPeerAddress (), m_boundnetdevice);
cfa1741013dd Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents: 7627
diff changeset
  2369
    }
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2370
  NS_LOG_LOGIC ("Schedule persist timeout at time "
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2371
                << Simulator::Now ().GetSeconds () << " to expire at time "
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2372
                << (Simulator::Now () + m_persistTimeout).GetSeconds ());
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2373
  m_persistEvent = Simulator::Schedule (m_persistTimeout, &TcpSocketBase::PersistTimeout, this);
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
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2376
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2377
TcpSocketBase::Retransmit ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2378
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2379
  m_nextTxSequence = m_txBuffer->HeadSequence (); // Start from highest Ack
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2380
  m_dupAckCount = 0;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2381
  DoRetransmit (); // Retransmit the packet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2382
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2383
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2384
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2385
TcpSocketBase::DoRetransmit ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2386
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2387
  NS_LOG_FUNCTION (this);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2388
  // Retransmit SYN packet
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2389
  if (m_state == SYN_SENT)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2390
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2391
      if (m_cnCount > 0)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2392
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2393
          SendEmptyPacket (TcpHeader::SYN);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2394
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2395
      else
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2396
        {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2397
          NotifyConnectionFailed ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2398
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2399
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2400
    }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2401
  // 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
  2402
  if (m_txBuffer->Size () == 0)
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2403
    {
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2404
      if (m_state == FIN_WAIT_1 || m_state == CLOSING)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2405
        { // Must have lost FIN, re-send
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2406
          SendEmptyPacket (TcpHeader::FIN);
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2407
        }
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2408
      return;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2409
    }
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2410
  // 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
  2411
  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
  2412
  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
  2413
  // 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
  2414
  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
  2415
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2416
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2417
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2418
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2419
TcpSocketBase::CancelAllTimers ()
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2420
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2421
  m_retxEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2422
  m_persistEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2423
  m_delAckEvent.Cancel ();
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2424
  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
  2425
  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
  2426
  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
  2427
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2428
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  2429
/* 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
  2430
void
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2431
TcpSocketBase::TimeWait ()
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2432
{
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2433
  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
  2434
  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
  2435
  CancelAllTimers ();
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2436
  // 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
  2437
  // 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
  2438
  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
  2439
                                         &TcpSocketBase::CloseAndNotify, this);
6694
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
10405
45c8fceae24e Doxygen fixes to Topology-read, Ipv6, and tcp-socket
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 10157
diff changeset
  2442
/* Below are the attribute get/set functions */
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2443
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2444
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2445
TcpSocketBase::SetSndBufSize (uint32_t size)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2446
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2447
  m_txBuffer->SetMaxBufferSize (size);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2448
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2449
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2450
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2451
TcpSocketBase::GetSndBufSize (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2452
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2453
  return m_txBuffer->MaxBufferSize ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2454
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2455
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2456
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2457
TcpSocketBase::SetRcvBufSize (uint32_t size)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2458
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2459
  m_rxBuffer->SetMaxBufferSize (size);
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
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2463
TcpSocketBase::GetRcvBufSize (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2464
{
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2465
  return m_rxBuffer->MaxBufferSize ();
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2466
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2467
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2468
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2469
TcpSocketBase::SetSegSize (uint32_t size)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2470
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2471
  m_segmentSize = size;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2472
  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
  2473
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2474
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2475
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2476
TcpSocketBase::GetSegSize (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2477
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2478
  return m_segmentSize;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2479
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2480
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2481
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2482
TcpSocketBase::SetConnTimeout (Time timeout)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2483
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2484
  m_cnTimeout = timeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2485
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2486
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2487
Time
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2488
TcpSocketBase::GetConnTimeout (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2489
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2490
  return m_cnTimeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2491
}
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
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2494
TcpSocketBase::SetConnCount (uint32_t count)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2495
{
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2496
  m_cnRetries = count;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2497
}
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
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2500
TcpSocketBase::GetConnCount (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2501
{
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2502
  return m_cnRetries;
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2503
}
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
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2506
TcpSocketBase::SetDelAckTimeout (Time timeout)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2507
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2508
  m_delAckTimeout = timeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2509
}
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
Time
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2512
TcpSocketBase::GetDelAckTimeout (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2513
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2514
  return m_delAckTimeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2515
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2516
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2517
void
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2518
TcpSocketBase::SetDelAckMaxCount (uint32_t count)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2519
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2520
  m_delAckMaxCount = count;
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
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2523
uint32_t
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2524
TcpSocketBase::GetDelAckMaxCount (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2525
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2526
  return m_delAckMaxCount;
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
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2529
void
7619
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2530
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
  2531
{
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2532
  m_noDelay = noDelay;
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2533
}
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2534
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2535
bool
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2536
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
  2537
{
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2538
  return m_noDelay;
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2539
}
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2540
b4dee6307aa7 Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7611
diff changeset
  2541
void
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2542
TcpSocketBase::SetPersistTimeout (Time timeout)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2543
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2544
  m_persistTimeout = timeout;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2545
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2546
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2547
Time
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2548
TcpSocketBase::GetPersistTimeout (void) const
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2549
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2550
  return m_persistTimeout;
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
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2553
bool
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2554
TcpSocketBase::SetAllowBroadcast (bool allowBroadcast)
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2555
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2556
  // 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
  2557
  return (!allowBroadcast);
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2558
}
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
bool
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2561
TcpSocketBase::GetAllowBroadcast (void) const
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2562
{
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2563
  return false;
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2564
}
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2565
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
  2566
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
  2567
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
  2568
{
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
  2569
  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
  2570
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
  2571
  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
  2572
    {
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
  2573
      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
  2574
        {
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
  2575
          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
  2576
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
  2577
          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
  2578
            {
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
  2579
              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
  2580
              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
  2581
              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
  2582
            }
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
  2583
        }
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
  2584
    }
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
  2585
11632
88d6e64c778c bug 2165: server replies to SYN (with option TS) with a SYNACK (with option TS) also if the attribute Timestamp is false
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11598
diff changeset
  2586
  bool timestampAttribute = m_timestampEnabled;
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
  2587
  m_timestampEnabled = false;
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2588
11632
88d6e64c778c bug 2165: server replies to SYN (with option TS) with a SYNACK (with option TS) also if the attribute Timestamp is false
Natale Patriciello <natale.patriciello@gmail.com>
parents: 11598
diff changeset
  2589
  if (header.HasOption (TcpOption::TS) && timestampAttribute)
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
  2590
    {
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
  2591
      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
  2592
      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
  2593
    }
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
  2594
}
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
  2595
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2596
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
  2597
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
  2598
{
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
  2599
  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
  2600
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
  2601
  // 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
  2602
  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
  2603
    {
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
  2604
      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
  2605
    }
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
  2606
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
  2607
  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
  2608
    {
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
  2609
      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
  2610
    }
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
}
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
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
  2614
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
  2615
{
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
  2616
  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
  2617
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
  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
  2619
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
  // 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
  2621
  // 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
  2622
  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
  2623
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
  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
  2625
    {
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
      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
  2627
      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
  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
  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
  2631
                 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
  2632
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2633
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
  2634
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
  2635
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
  2636
{
10911
c224a92a02a2 add some logging
Tom Henderson <tomh@tomh.org>
parents: 10907
diff changeset
  2637
  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
  2638
  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
  2639
  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
  2640
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
  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
  2642
    {
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
      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
  2644
      ++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
  2645
    }
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
  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
  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
      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
  2650
      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
  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
10911
c224a92a02a2 add some logging
Tom Henderson <tomh@tomh.org>
parents: 10907
diff changeset
  2653
  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
  2654
               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
  2655
  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
  2656
}
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
7608
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2658
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
  2659
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
  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
  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
  2662
  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
  2663
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
  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
  2665
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
  // 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
  2667
  // 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
  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
  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
  2670
  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
  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
  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
  2673
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
  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
  2675
                 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
  2676
}
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
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
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
  2679
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
  2680
{
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
  2681
  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
  2682
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
  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
  2684
  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
  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
  NS_LOG_INFO (m_node->GetId () << " Got timestamp=" <<
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2687
               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
  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
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
  2691
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
  2692
{
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
  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
  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
  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
  2696
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
  2697
  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
  2698
  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
  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
  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
  2701
  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
  2702
               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
  2703
}
de67936e4017 Mixed bugfixes on TCP, closes bug 1166, 1227, 1242.
Adrian S Tam <adrian.sw.tam@gmail.com>
parents: 7441
diff changeset
  2704
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
  2705
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
  2706
{
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
  2707
  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
  2708
  //  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
  2709
  //  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
  2710
  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
  2711
  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
  2712
  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
  2713
  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
  2714
    {
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
  2715
      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
  2716
      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
  2717
      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
  2718
    }
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
  2719
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
  2720
  // 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
  2721
  // 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
  2722
  // 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
  2723
  // 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
  2724
  // (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
  2725
  // 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
  2726
  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
  2727
  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
  2728
    {
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
  2729
      // 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
  2730
      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
  2731
    }
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
  2732
  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
  2733
    {
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
  2734
      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
  2735
      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
  2736
    }
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
  2737
  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
  2738
    {
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
  2739
      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
  2740
      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
  2741
    }
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
  2742
  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
  2743
    {
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
  2744
      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
  2745
      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
  2746
    }
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
  2747
}
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
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2749
void
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2750
TcpSocketBase::SetMinRto (Time minRto)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2751
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2752
  NS_LOG_FUNCTION (this << minRto);
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2753
  m_minRto = minRto;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2754
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2755
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2756
Time
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2757
TcpSocketBase::GetMinRto (void) const
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2758
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2759
  return m_minRto;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2760
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2761
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2762
void
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2763
TcpSocketBase::SetClockGranularity (Time clockGranularity)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2764
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2765
  NS_LOG_FUNCTION (this << clockGranularity);
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2766
  m_clockGranularity = clockGranularity;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2767
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2768
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2769
Time
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2770
TcpSocketBase::GetClockGranularity (void) const
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2771
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2772
  return m_clockGranularity;
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2773
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2774
11195
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2775
Ptr<TcpTxBuffer>
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2776
TcpSocketBase::GetTxBuffer (void) const
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2777
{
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2778
  return m_txBuffer;
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2779
}
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2780
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2781
Ptr<TcpRxBuffer>
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2782
TcpSocketBase::GetRxBuffer (void) const
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2783
{
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2784
  return m_rxBuffer;
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2785
}
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2786
0c5e9bfa1b48 Bug 2055 - TxBuffer and RxBuffer traces don't work
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11193
diff changeset
  2787
11190
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2788
//RttHistory methods
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2789
RttHistory::RttHistory (SequenceNumber32 s, uint32_t c, Time t)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2790
  : seq (s), count (c), time (t), retx (false)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2791
{
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2792
}
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2793
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2794
RttHistory::RttHistory (const RttHistory& h)
f0458968b67d Bug 1405 - RttEstimator improvements
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 11044
diff changeset
  2795
  : 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
  2796
{
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
6694
a814f37d15bf merge new TCP code
Josh Pelkey <jpelkey@gatech.edu>
parents:
diff changeset
  2799
} // namespace ns3