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