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