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