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