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