author | Ken Renard <kdrenard2@gmail.com> |
Mon, 20 Feb 2012 14:05:07 +0100 | |
changeset 7717 | cfa1741013dd |
parent 7704 | aef733235832 |
child 7720 | 63b434b229bc |
permissions | -rw-r--r-- |
7385
10beb0e53130
standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents:
7257
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
3578 | 2 |
/* |
3 |
* This program is free software; you can redistribute it and/or modify |
|
4 |
* it under the terms of the GNU General Public License version 2 as |
|
5 |
* published by the Free Software Foundation; |
|
6 |
* |
|
7 |
* This program is distributed in the hope that it will be useful, |
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
10 |
* GNU General Public License for more details. |
|
11 |
* |
|
12 |
* You should have received a copy of the GNU General Public License |
|
13 |
* along with this program; if not, write to the Free Software |
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
* |
|
16 |
* based on tcp-socket-impl.cc, Author: Raj Bhattacharjea <raj.b@gatech.edu> |
|
17 |
* Author: Florian Westphal <fw@strlen.de> |
|
18 |
*/ |
|
19 |
||
5887 | 20 |
#define NS_LOG_APPEND_CONTEXT \ |
21 |
if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; } |
|
22 |
||
3578 | 23 |
#include "ns3/node.h" |
24 |
#include "ns3/inet-socket-address.h" |
|
25 |
#include "ns3/log.h" |
|
26 |
#include "ns3/ipv4.h" |
|
27 |
#include "ipv4-end-point.h" |
|
28 |
#include "nsc-tcp-l4-protocol.h" |
|
29 |
#include "nsc-tcp-socket-impl.h" |
|
30 |
#include "ns3/simulation-singleton.h" |
|
31 |
#include "ns3/simulator.h" |
|
32 |
#include "ns3/packet.h" |
|
33 |
#include "ns3/uinteger.h" |
|
34 |
#include "ns3/trace-source-accessor.h" |
|
35 |
||
36 |
#include <algorithm> |
|
37 |
||
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
38 |
// for ntohs(). |
3578 | 39 |
#include <arpa/inet.h> |
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
40 |
#include <netinet/in.h> |
6694 | 41 |
#include "sim_interface.h" |
3578 | 42 |
|
3635
cddd59578812
compile nsc code unconditionally.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3589
diff
changeset
|
43 |
#include "sim_errno.h" |
3578 | 44 |
|
45 |
NS_LOG_COMPONENT_DEFINE ("NscTcpSocketImpl"); |
|
46 |
||
47 |
using namespace std; |
|
48 |
||
49 |
namespace ns3 { |
|
50 |
||
51 |
NS_OBJECT_ENSURE_REGISTERED (NscTcpSocketImpl); |
|
52 |
||
53 |
TypeId |
|
54 |
NscTcpSocketImpl::GetTypeId () |
|
55 |
{ |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
56 |
static TypeId tid = TypeId ("ns3::NscTcpSocketImpl") |
3578 | 57 |
.SetParent<TcpSocket> () |
58 |
.AddTraceSource ("CongestionWindow", |
|
59 |
"The TCP connection's congestion window", |
|
60 |
MakeTraceSourceAccessor (&NscTcpSocketImpl::m_cWnd)) |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
61 |
; |
3578 | 62 |
return tid; |
63 |
} |
|
64 |
||
6694 | 65 |
NscTcpSocketImpl::NscTcpSocketImpl () |
3578 | 66 |
: m_endPoint (0), |
67 |
m_node (0), |
|
68 |
m_tcp (0), |
|
3778
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
69 |
m_localAddress (Ipv4Address::GetZero ()), |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
70 |
m_localPort (0), |
3578 | 71 |
m_peerAddress ("0.0.0.0", 0), |
72 |
m_errno (ERROR_NOTERROR), |
|
73 |
m_shutdownSend (false), |
|
74 |
m_shutdownRecv (false), |
|
75 |
m_connected (false), |
|
76 |
m_state (CLOSED), |
|
77 |
m_closeOnEmpty (false), |
|
78 |
m_txBufferSize (0), |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
79 |
m_lastMeasuredRtt (Seconds (0.0)) |
3578 | 80 |
{ |
81 |
NS_LOG_FUNCTION (this); |
|
82 |
} |
|
83 |
||
84 |
NscTcpSocketImpl::NscTcpSocketImpl(const NscTcpSocketImpl& sock) |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
85 |
: TcpSocket (sock), //copy the base class callbacks |
3578 | 86 |
m_delAckMaxCount (sock.m_delAckMaxCount), |
87 |
m_delAckTimeout (sock.m_delAckTimeout), |
|
7619
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
88 |
m_noDelay (sock.m_noDelay), |
3578 | 89 |
m_endPoint (0), |
90 |
m_node (sock.m_node), |
|
91 |
m_tcp (sock.m_tcp), |
|
92 |
m_remoteAddress (sock.m_remoteAddress), |
|
93 |
m_remotePort (sock.m_remotePort), |
|
94 |
m_localAddress (sock.m_localAddress), |
|
95 |
m_localPort (sock.m_localPort), |
|
96 |
m_peerAddress (sock.m_peerAddress), |
|
97 |
m_errno (sock.m_errno), |
|
98 |
m_shutdownSend (sock.m_shutdownSend), |
|
99 |
m_shutdownRecv (sock.m_shutdownRecv), |
|
100 |
m_connected (sock.m_connected), |
|
101 |
m_state (sock.m_state), |
|
102 |
m_closeOnEmpty (sock.m_closeOnEmpty), |
|
6319
2b1bbc8d0c58
bug 906: NSC TCP socket fork did not copy txbuffersize over
Antti Mäkelä <zarhan@cc.hut.fi>
parents:
5971
diff
changeset
|
103 |
m_txBufferSize (sock.m_txBufferSize), |
3578 | 104 |
m_segmentSize (sock.m_segmentSize), |
105 |
m_rxWindowSize (sock.m_rxWindowSize), |
|
106 |
m_advertisedWindowSize (sock.m_advertisedWindowSize), |
|
107 |
m_cWnd (sock.m_cWnd), |
|
108 |
m_ssThresh (sock.m_ssThresh), |
|
109 |
m_initialCWnd (sock.m_initialCWnd), |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
110 |
m_lastMeasuredRtt (Seconds (0.0)), |
3578 | 111 |
m_cnTimeout (sock.m_cnTimeout), |
112 |
m_cnCount (sock.m_cnCount), |
|
113 |
m_rxAvailable (0), |
|
114 |
m_nscTcpSocket (0), |
|
115 |
m_sndBufSize (sock.m_sndBufSize) |
|
116 |
{ |
|
117 |
NS_LOG_FUNCTION_NOARGS (); |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
118 |
NS_LOG_LOGIC ("Invoked the copy constructor"); |
3578 | 119 |
//copy the pending data if necessary |
120 |
if(!sock.m_txBuffer.empty () ) |
|
121 |
{ |
|
122 |
m_txBuffer = sock.m_txBuffer; |
|
123 |
} |
|
124 |
//can't "copy" the endpoint just yes, must do this when we know the peer info |
|
125 |
//too; this is in SYN_ACK_TX |
|
126 |
} |
|
127 |
||
128 |
NscTcpSocketImpl::~NscTcpSocketImpl () |
|
129 |
{ |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
130 |
NS_LOG_FUNCTION (this); |
3578 | 131 |
m_node = 0; |
132 |
if (m_endPoint != 0) |
|
133 |
{ |
|
134 |
NS_ASSERT (m_tcp != 0); |
|
135 |
/** |
|
136 |
* Note that this piece of code is a bit tricky: |
|
137 |
* when DeAllocate is called, it will call into |
|
138 |
* Ipv4EndPointDemux::Deallocate which triggers |
|
139 |
* a delete of the associated endPoint which triggers |
|
7600
57ba46094a0d
fix various doxygen errors
Vedran Miletić <rivanvx@gmail.com>
parents:
7386
diff
changeset
|
140 |
* in turn a call to the method NscTcpSocketImpl::Destroy below |
3578 | 141 |
* will will zero the m_endPoint field. |
142 |
*/ |
|
143 |
NS_ASSERT (m_endPoint != 0); |
|
144 |
m_tcp->DeAllocate (m_endPoint); |
|
145 |
NS_ASSERT (m_endPoint == 0); |
|
146 |
} |
|
147 |
m_tcp = 0; |
|
148 |
} |
|
149 |
||
150 |
void |
|
151 |
NscTcpSocketImpl::SetNode (Ptr<Node> node) |
|
152 |
{ |
|
153 |
m_node = node; |
|
154 |
// Initialize some variables |
|
155 |
m_cWnd = m_initialCWnd * m_segmentSize; |
|
156 |
m_rxWindowSize = m_advertisedWindowSize; |
|
157 |
} |
|
158 |
||
159 |
void |
|
160 |
NscTcpSocketImpl::SetTcp (Ptr<NscTcpL4Protocol> tcp) |
|
161 |
{ |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
162 |
m_nscTcpSocket = tcp->m_nscStack->new_tcp_socket (); |
3578 | 163 |
m_tcp = tcp; |
164 |
} |
|
165 |
||
166 |
||
167 |
enum Socket::SocketErrno |
|
168 |
NscTcpSocketImpl::GetErrno (void) const |
|
169 |
{ |
|
170 |
NS_LOG_FUNCTION_NOARGS (); |
|
171 |
return m_errno; |
|
172 |
} |
|
173 |
||
6689
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
174 |
enum Socket::SocketType |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
175 |
NscTcpSocketImpl::GetSocketType (void) const |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
176 |
{ |
6692
591fb1aa0ca4
Avoid enum name collision in socket
Josh Pelkey <jpelkey@gatech.edu>
parents:
6689
diff
changeset
|
177 |
return NS3_SOCK_STREAM; |
6689
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
178 |
} |
e2de571e920a
Implement Socket::GetSocketType
Josh Pelkey <jpelkey@gatech.edu>
parents:
6549
diff
changeset
|
179 |
|
3578 | 180 |
Ptr<Node> |
181 |
NscTcpSocketImpl::GetNode (void) const |
|
182 |
{ |
|
183 |
NS_LOG_FUNCTION_NOARGS (); |
|
184 |
return m_node; |
|
185 |
} |
|
186 |
||
187 |
void |
|
188 |
NscTcpSocketImpl::Destroy (void) |
|
189 |
{ |
|
190 |
NS_LOG_FUNCTION_NOARGS (); |
|
191 |
m_node = 0; |
|
192 |
m_endPoint = 0; |
|
193 |
m_tcp = 0; |
|
194 |
} |
|
195 |
int |
|
196 |
NscTcpSocketImpl::FinishBind (void) |
|
197 |
{ |
|
198 |
NS_LOG_FUNCTION_NOARGS (); |
|
199 |
if (m_endPoint == 0) |
|
200 |
{ |
|
201 |
return -1; |
|
202 |
} |
|
203 |
m_endPoint->SetRxCallback (MakeCallback (&NscTcpSocketImpl::ForwardUp, Ptr<NscTcpSocketImpl>(this))); |
|
204 |
m_endPoint->SetDestroyCallback (MakeCallback (&NscTcpSocketImpl::Destroy, Ptr<NscTcpSocketImpl>(this))); |
|
205 |
m_localAddress = m_endPoint->GetLocalAddress (); |
|
206 |
m_localPort = m_endPoint->GetLocalPort (); |
|
207 |
return 0; |
|
208 |
} |
|
209 |
||
210 |
int |
|
211 |
NscTcpSocketImpl::Bind (void) |
|
212 |
{ |
|
213 |
NS_LOG_FUNCTION_NOARGS (); |
|
214 |
m_endPoint = m_tcp->Allocate (); |
|
215 |
return FinishBind (); |
|
216 |
} |
|
7717
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7704
diff
changeset
|
217 |
int |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7704
diff
changeset
|
218 |
NscTcpSocketImpl::Bind6 () |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7704
diff
changeset
|
219 |
{ |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7704
diff
changeset
|
220 |
NS_LOG_LOGIC ("NscTcpSocketImpl: ERROR_AFNOSUPPORT - Bind6 not supported".); |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7704
diff
changeset
|
221 |
m_errno = ERROR_AFNOSUPPORT; |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7704
diff
changeset
|
222 |
return (-1); |
cfa1741013dd
Add support for IPv6 transport protocols
Ken Renard <kdrenard2@gmail.com>
parents:
7704
diff
changeset
|
223 |
} |
3578 | 224 |
int |
225 |
NscTcpSocketImpl::Bind (const Address &address) |
|
226 |
{ |
|
227 |
NS_LOG_FUNCTION (this<<address); |
|
228 |
if (!InetSocketAddress::IsMatchingType (address)) |
|
229 |
{ |
|
230 |
return ERROR_INVAL; |
|
231 |
} |
|
232 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
|
233 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
|
234 |
uint16_t port = transport.GetPort (); |
|
235 |
if (ipv4 == Ipv4Address::GetAny () && port == 0) |
|
236 |
{ |
|
237 |
m_endPoint = m_tcp->Allocate (); |
|
5888 | 238 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 239 |
} |
240 |
else if (ipv4 == Ipv4Address::GetAny () && port != 0) |
|
241 |
{ |
|
242 |
m_endPoint = m_tcp->Allocate (port); |
|
5888 | 243 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 244 |
} |
245 |
else if (ipv4 != Ipv4Address::GetAny () && port == 0) |
|
246 |
{ |
|
247 |
m_endPoint = m_tcp->Allocate (ipv4); |
|
5888 | 248 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 249 |
} |
250 |
else if (ipv4 != Ipv4Address::GetAny () && port != 0) |
|
251 |
{ |
|
252 |
m_endPoint = m_tcp->Allocate (ipv4, port); |
|
5888 | 253 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 254 |
} |
255 |
||
256 |
m_localPort = port; |
|
257 |
return FinishBind (); |
|
258 |
} |
|
259 |
||
260 |
int |
|
261 |
NscTcpSocketImpl::ShutdownSend (void) |
|
262 |
{ |
|
263 |
NS_LOG_FUNCTION_NOARGS (); |
|
264 |
m_shutdownSend = true; |
|
265 |
return 0; |
|
266 |
} |
|
267 |
int |
|
268 |
NscTcpSocketImpl::ShutdownRecv (void) |
|
269 |
{ |
|
270 |
NS_LOG_FUNCTION_NOARGS (); |
|
4491
893d48fcf7f3
bug 535: UDP/TCP ShutdownRecv incorrect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3869
diff
changeset
|
271 |
m_shutdownRecv = true; |
3578 | 272 |
return 0; |
273 |
} |
|
274 |
||
275 |
int |
|
276 |
NscTcpSocketImpl::Close (void) |
|
277 |
{ |
|
278 |
NS_LOG_FUNCTION (this << m_state); |
|
279 |
||
280 |
if (m_state == CLOSED) |
|
281 |
{ |
|
282 |
return -1; |
|
283 |
} |
|
284 |
if (!m_txBuffer.empty ()) |
|
285 |
{ // App close with pending data must wait until all data transmitted |
|
286 |
m_closeOnEmpty = true; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
287 |
NS_LOG_LOGIC ("Socket " << this << |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
288 |
" deferring close, state " << m_state); |
3578 | 289 |
return 0; |
290 |
} |
|
291 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
292 |
NS_LOG_LOGIC ("NscTcp socket " << this << " calling disconnect(); moving to CLOSED"); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
293 |
m_nscTcpSocket->disconnect (); |
3578 | 294 |
m_state = CLOSED; |
295 |
ShutdownSend (); |
|
296 |
return 0; |
|
297 |
} |
|
298 |
||
299 |
int |
|
300 |
NscTcpSocketImpl::Connect (const Address & address) |
|
301 |
{ |
|
302 |
NS_LOG_FUNCTION (this << address); |
|
303 |
if (m_endPoint == 0) |
|
304 |
{ |
|
305 |
if (Bind () == -1) |
|
306 |
{ |
|
307 |
NS_ASSERT (m_endPoint == 0); |
|
308 |
return -1; |
|
309 |
} |
|
310 |
NS_ASSERT (m_endPoint != 0); |
|
311 |
} |
|
312 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
|
313 |
m_remoteAddress = transport.GetIpv4 (); |
|
314 |
m_remotePort = transport.GetPort (); |
|
315 |
||
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
316 |
std::ostringstream ss; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
317 |
m_remoteAddress.Print (ss); |
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
318 |
std::string ipstring = ss.str (); |
3578 | 319 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
320 |
m_nscTcpSocket->connect (ipstring.c_str (), m_remotePort); |
3578 | 321 |
m_state = SYN_SENT; |
322 |
return 0; |
|
323 |
} |
|
324 |
||
325 |
int |
|
326 |
NscTcpSocketImpl::Send (const Ptr<Packet> p, uint32_t flags) |
|
327 |
{ |
|
328 |
NS_LOG_FUNCTION (this << p); |
|
329 |
||
330 |
NS_ASSERT (p->GetSize () > 0); |
|
331 |
if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) |
|
332 |
{ |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
333 |
if (p->GetSize () > GetTxAvailable ()) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
334 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
335 |
m_errno = ERROR_MSGSIZE; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
336 |
return -1; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
337 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
338 |
|
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
339 |
uint32_t sent = p->GetSize (); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
340 |
if (m_state == ESTABLISHED) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
341 |
{ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
342 |
m_txBuffer.push (p); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
343 |
m_txBufferSize += sent; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
344 |
SendPendingData (); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
345 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
346 |
else |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
347 |
{ // SYN_SET -- Queue Data |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
348 |
m_txBuffer.push (p); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
349 |
m_txBufferSize += sent; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
350 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
351 |
return sent; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
352 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
353 |
else |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
354 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
355 |
m_errno = ERROR_NOTCONN; |
3578 | 356 |
return -1; |
357 |
} |
|
358 |
} |
|
359 |
||
360 |
int |
|
361 |
NscTcpSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags, const Address &address) |
|
362 |
{ |
|
363 |
NS_LOG_FUNCTION (this << address << p); |
|
364 |
if (!m_connected) |
|
365 |
{ |
|
366 |
m_errno = ERROR_NOTCONN; |
|
367 |
return -1; |
|
368 |
} |
|
369 |
else |
|
370 |
{ |
|
371 |
return Send (p, flags); //drop the address according to BSD manpages |
|
372 |
} |
|
373 |
} |
|
374 |
||
375 |
uint32_t |
|
376 |
NscTcpSocketImpl::GetTxAvailable (void) const |
|
377 |
{ |
|
378 |
NS_LOG_FUNCTION_NOARGS (); |
|
379 |
if (m_txBufferSize != 0) |
|
380 |
{ |
|
381 |
NS_ASSERT (m_txBufferSize <= m_sndBufSize); |
|
382 |
return m_sndBufSize - m_txBufferSize; |
|
383 |
} |
|
384 |
else |
|
385 |
{ |
|
386 |
return m_sndBufSize; |
|
387 |
} |
|
388 |
} |
|
389 |
||
390 |
int |
|
3772
f0d8608ab155
Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents:
3711
diff
changeset
|
391 |
NscTcpSocketImpl::Listen (void) |
3578 | 392 |
{ |
3772
f0d8608ab155
Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents:
3711
diff
changeset
|
393 |
NS_LOG_FUNCTION (this); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
394 |
m_nscTcpSocket->listen (m_localPort); |
3578 | 395 |
m_state = LISTEN; |
396 |
return 0; |
|
397 |
} |
|
398 |
||
399 |
||
400 |
void |
|
401 |
NscTcpSocketImpl::NSCWakeup () |
|
402 |
{ |
|
403 |
switch (m_state) { |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
404 |
case SYN_SENT: |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
405 |
if (!m_nscTcpSocket->is_connected ()) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
406 |
break; |
3578 | 407 |
m_state = ESTABLISHED; |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
408 |
Simulator::ScheduleNow (&NscTcpSocketImpl::ConnectionSucceeded, this); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
409 |
// fall through to schedule read/write events |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
410 |
case ESTABLISHED: |
3578 | 411 |
if (!m_txBuffer.empty ()) |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
412 |
Simulator::ScheduleNow (&NscTcpSocketImpl::SendPendingData, this); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
413 |
Simulator::ScheduleNow (&NscTcpSocketImpl::ReadPendingData, this); |
3578 | 414 |
break; |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
415 |
case LISTEN: |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
416 |
Simulator::ScheduleNow (&NscTcpSocketImpl::Accept, this); |
3578 | 417 |
break; |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
418 |
case CLOSED: break; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
419 |
default: |
3578 | 420 |
NS_LOG_DEBUG (this << " invalid state: " << m_state); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
421 |
} |
3578 | 422 |
} |
423 |
||
424 |
Ptr<Packet> |
|
425 |
NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags) |
|
426 |
{ |
|
427 |
NS_LOG_FUNCTION_NOARGS (); |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
428 |
if (m_deliveryQueue.empty () ) |
3578 | 429 |
{ |
3780
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
430 |
m_errno = ERROR_AGAIN; |
3578 | 431 |
return 0; |
432 |
} |
|
433 |
Ptr<Packet> p = m_deliveryQueue.front (); |
|
434 |
if (p->GetSize () <= maxSize) |
|
435 |
{ |
|
436 |
m_deliveryQueue.pop (); |
|
437 |
m_rxAvailable -= p->GetSize (); |
|
438 |
} |
|
439 |
else |
|
440 |
{ |
|
3780
317ccc4ebb4e
bug 386: make sure errno is not set incorrectly and don't access stale packets.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3778
diff
changeset
|
441 |
m_errno = ERROR_AGAIN; |
3578 | 442 |
p = 0; |
443 |
} |
|
444 |
return p; |
|
445 |
} |
|
446 |
||
447 |
Ptr<Packet> |
|
448 |
NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
449 |
Address &fromAddress) |
3578 | 450 |
{ |
451 |
NS_LOG_FUNCTION (this << maxSize << flags); |
|
452 |
Ptr<Packet> packet = Recv (maxSize, flags); |
|
453 |
if (packet != 0) |
|
454 |
{ |
|
455 |
SocketAddressTag tag; |
|
456 |
bool found; |
|
4523
b8bdc36a3355
use packet tags rather than byte tags to match TcpSocketImpl and UdpSocketImpl
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4516
diff
changeset
|
457 |
found = packet->PeekPacketTag (tag); |
3578 | 458 |
NS_ASSERT (found); |
459 |
fromAddress = tag.GetAddress (); |
|
460 |
} |
|
461 |
return packet; |
|
462 |
} |
|
463 |
||
3778
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
464 |
int |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
465 |
NscTcpSocketImpl::GetSockName (Address &address) const |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
466 |
{ |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
467 |
NS_LOG_FUNCTION_NOARGS (); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
468 |
address = InetSocketAddress (m_localAddress, m_localPort); |
3778
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
469 |
return 0; |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
470 |
} |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
471 |
|
3578 | 472 |
uint32_t |
473 |
NscTcpSocketImpl::GetRxAvailable (void) const |
|
474 |
{ |
|
475 |
NS_LOG_FUNCTION_NOARGS (); |
|
476 |
// We separately maintain this state to avoid walking the queue |
|
477 |
// every time this might be called |
|
478 |
return m_rxAvailable; |
|
479 |
} |
|
480 |
||
481 |
void |
|
6442
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
482 |
NscTcpSocketImpl::ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port, |
f380cf1aa4d8
Bug 671 add packet-info-tag.cc for IP_PKTINFO/IPV6_PKTINFO
Hajime Tazaki <tazaki@sfc.wide.ad.jp>
parents:
6437
diff
changeset
|
483 |
Ptr<Ipv4Interface> incomingInterface) |
3578 | 484 |
{ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
485 |
NSCWakeup (); |
3578 | 486 |
} |
487 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
488 |
void NscTcpSocketImpl::CompleteFork (void) |
3578 | 489 |
{ |
490 |
// The address pairs (m_localAddress, m_localPort, m_remoteAddress, m_remotePort) |
|
491 |
// are bogus, but this isn't important at the moment, because |
|
492 |
// address <-> Socket handling is done by NSC internally. |
|
493 |
// We only need to add the new ns-3 socket to the list of sockets, so |
|
494 |
// we use plain Allocate() instead of Allocate(m_localAddress, ... ) |
|
3869
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
495 |
struct sockaddr_in sin; |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
496 |
size_t sin_len = sizeof(sin); |
3578 | 497 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
498 |
if (0 == m_nscTcpSocket->getpeername ((struct sockaddr*) &sin, &sin_len)) { |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
499 |
m_remotePort = ntohs (sin.sin_port); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
500 |
m_remoteAddress = m_remoteAddress.Deserialize ((const uint8_t*) &sin.sin_addr); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
501 |
m_peerAddress = InetSocketAddress (m_remoteAddress, m_remotePort); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
502 |
} |
3578 | 503 |
|
504 |
m_endPoint = m_tcp->Allocate (); |
|
505 |
||
506 |
//the cloned socket with be in listen state, so manually change state |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
507 |
NS_ASSERT (m_state == LISTEN); |
3578 | 508 |
m_state = ESTABLISHED; |
509 |
||
3869
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
510 |
sin_len = sizeof(sin); |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
511 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
512 |
if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len)) |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
513 |
m_localAddress = m_localAddress.Deserialize ((const uint8_t*) &sin.sin_addr); |
3578 | 514 |
|
515 |
NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " accepted connection from " |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
516 |
<< m_remoteAddress << ":" << m_remotePort |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
517 |
<< " to " << m_localAddress << ":" << m_localPort); |
3578 | 518 |
//equivalent to FinishBind |
519 |
m_endPoint->SetRxCallback (MakeCallback (&NscTcpSocketImpl::ForwardUp, Ptr<NscTcpSocketImpl>(this))); |
|
520 |
m_endPoint->SetDestroyCallback (MakeCallback (&NscTcpSocketImpl::Destroy, Ptr<NscTcpSocketImpl>(this))); |
|
521 |
||
522 |
NotifyNewConnectionCreated (this, m_peerAddress); |
|
523 |
} |
|
524 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
525 |
void NscTcpSocketImpl::ConnectionSucceeded () |
3578 | 526 |
{ // We would preferred to have scheduled an event directly to |
527 |
// NotifyConnectionSucceeded, but (sigh) these are protected |
|
528 |
// and we can get the address of it :( |
|
3869
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
529 |
struct sockaddr_in sin; |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
530 |
size_t sin_len = sizeof(sin); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
531 |
if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len)) { |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
532 |
m_localAddress = m_localAddress.Deserialize ((const uint8_t*)&sin.sin_addr); |
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
533 |
m_localPort = ntohs (sin.sin_port); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
534 |
} |
3578 | 535 |
|
536 |
NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to " |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
537 |
<< m_remoteAddress << ":" << m_remotePort |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
538 |
<< " from " << m_localAddress << ":" << m_localPort); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
539 |
NotifyConnectionSucceeded (); |
3578 | 540 |
} |
541 |
||
542 |
||
543 |
bool NscTcpSocketImpl::Accept (void) |
|
544 |
{ |
|
545 |
if (m_state == CLOSED) |
|
546 |
{ // Happens if application closes listening socket after Accept() was scheduled. |
|
547 |
return false; |
|
548 |
} |
|
549 |
NS_ASSERT (m_state == LISTEN); |
|
550 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
551 |
if (!m_nscTcpSocket->is_listening ()) |
3578 | 552 |
{ |
553 |
return false; |
|
554 |
} |
|
555 |
INetStreamSocket *newsock; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
556 |
int res = m_nscTcpSocket->accept (&newsock); |
3578 | 557 |
if (res != 0) |
558 |
{ |
|
559 |
return false; |
|
560 |
} |
|
561 |
// We could obtain a fromAddress using getpeername, but we've already |
|
562 |
// finished the tcp handshake here, i.e. this is a new connection |
|
563 |
// and not a connection request. |
|
564 |
// if (!NotifyConnectionRequest(fromAddress)) |
|
565 |
// return true; |
|
566 |
||
567 |
// Clone the socket |
|
568 |
Ptr<NscTcpSocketImpl> newSock = Copy (); |
|
569 |
newSock->m_nscTcpSocket = newsock; |
|
570 |
NS_LOG_LOGIC ("Cloned a NscTcpSocketImpl " << newSock); |
|
571 |
||
572 |
Simulator::ScheduleNow (&NscTcpSocketImpl::CompleteFork, newSock); |
|
573 |
return true; |
|
574 |
} |
|
575 |
||
576 |
bool NscTcpSocketImpl::ReadPendingData (void) |
|
577 |
{ |
|
578 |
if (m_state != ESTABLISHED) |
|
579 |
{ |
|
580 |
return false; |
|
581 |
} |
|
582 |
int len, err; |
|
583 |
uint8_t buffer[8192]; |
|
584 |
len = sizeof(buffer); |
|
585 |
m_errno = ERROR_NOTERROR; |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
586 |
err = m_nscTcpSocket->read_data (buffer, &len); |
3578 | 587 |
if (err == 0 && len == 0) |
588 |
{ |
|
589 |
NS_LOG_LOGIC ("ReadPendingData got EOF from socket"); |
|
5889
526381e48c1d
Fix NSC improper response to FIN
Tom Henderson <tomh@tomh.org>
parents:
5888
diff
changeset
|
590 |
m_state = CLOSE_WAIT; |
3578 | 591 |
return false; |
592 |
} |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
593 |
m_errno = GetNativeNs3Errno (err); |
3578 | 594 |
switch (m_errno) |
595 |
{ |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
596 |
case ERROR_NOTERROR: break; // some data was sent |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
597 |
case ERROR_AGAIN: return false; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
598 |
default: |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
599 |
NS_LOG_WARN ("Error (" << err << ") " << |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
600 |
"during read_data, ns-3 errno set to" << m_errno); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
601 |
m_state = CLOSED; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
602 |
return false; |
3578 | 603 |
} |
604 |
||
605 |
Ptr<Packet> p = Create<Packet> (buffer, len); |
|
606 |
||
607 |
SocketAddressTag tag; |
|
608 |
||
609 |
tag.SetAddress (m_peerAddress); |
|
4523
b8bdc36a3355
use packet tags rather than byte tags to match TcpSocketImpl and UdpSocketImpl
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4516
diff
changeset
|
610 |
p->AddPacketTag (tag); |
3578 | 611 |
m_deliveryQueue.push (p); |
612 |
m_rxAvailable += p->GetSize (); |
|
613 |
||
614 |
NotifyDataRecv (); |
|
615 |
return true; |
|
616 |
} |
|
617 |
||
618 |
bool NscTcpSocketImpl::SendPendingData (void) |
|
619 |
{ |
|
620 |
NS_LOG_FUNCTION (this); |
|
621 |
NS_LOG_LOGIC ("ENTERING SendPendingData"); |
|
622 |
||
623 |
if (m_txBuffer.empty ()) |
|
624 |
{ |
|
625 |
return false; |
|
626 |
} |
|
627 |
||
628 |
int ret; |
|
629 |
size_t size, written = 0; |
|
630 |
||
631 |
do { |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
632 |
NS_ASSERT (!m_txBuffer.empty ()); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
633 |
Ptr<Packet> &p = m_txBuffer.front (); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
634 |
size = p->GetSize (); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
635 |
NS_ASSERT (size > 0); |
3578 | 636 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
637 |
m_errno = ERROR_NOTERROR; |
6549
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
638 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
639 |
uint8_t *buf = new uint8_t[size]; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
640 |
p->CopyData (buf, size); |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
641 |
ret = m_nscTcpSocket->send_data ((const char *)buf, size); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
642 |
delete[] buf; |
6549
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
643 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
644 |
if (ret <= 0) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
645 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
646 |
break; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
647 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
648 |
written += ret; |
3578 | 649 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
650 |
NS_ASSERT (m_txBufferSize >= (size_t)ret); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
651 |
m_txBufferSize -= ret; |
3578 | 652 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
653 |
if ((size_t)ret < size) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
654 |
{ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
655 |
p->RemoveAtStart (ret); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
656 |
break; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
657 |
} |
3578 | 658 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
659 |
m_txBuffer.pop (); |
3578 | 660 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
661 |
if (m_txBuffer.empty ()) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
662 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
663 |
if (m_closeOnEmpty) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
664 |
{ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
665 |
m_nscTcpSocket->disconnect (); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
666 |
m_state = CLOSED; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
667 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
668 |
break; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
669 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
670 |
} while ((size_t) ret == size); |
3578 | 671 |
|
672 |
if (written > 0) |
|
673 |
{ |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
674 |
Simulator::ScheduleNow (&NscTcpSocketImpl::NotifyDataSent, this, ret); |
3578 | 675 |
return true; |
676 |
} |
|
677 |
return false; |
|
678 |
} |
|
679 |
||
680 |
Ptr<NscTcpSocketImpl> NscTcpSocketImpl::Copy () |
|
681 |
{ |
|
682 |
return CopyObject<NscTcpSocketImpl> (this); |
|
683 |
} |
|
684 |
||
685 |
void |
|
686 |
NscTcpSocketImpl::SetSndBufSize (uint32_t size) |
|
687 |
{ |
|
688 |
m_sndBufSize = size; |
|
689 |
} |
|
690 |
||
691 |
uint32_t |
|
692 |
NscTcpSocketImpl::GetSndBufSize (void) const |
|
693 |
{ |
|
694 |
return m_sndBufSize; |
|
695 |
} |
|
696 |
||
697 |
void |
|
698 |
NscTcpSocketImpl::SetRcvBufSize (uint32_t size) |
|
699 |
{ |
|
700 |
m_rcvBufSize = size; |
|
701 |
} |
|
702 |
||
703 |
uint32_t |
|
704 |
NscTcpSocketImpl::GetRcvBufSize (void) const |
|
705 |
{ |
|
706 |
return m_rcvBufSize; |
|
707 |
} |
|
708 |
||
709 |
void |
|
710 |
NscTcpSocketImpl::SetSegSize (uint32_t size) |
|
711 |
{ |
|
712 |
m_segmentSize = size; |
|
713 |
} |
|
714 |
||
715 |
uint32_t |
|
716 |
NscTcpSocketImpl::GetSegSize (void) const |
|
717 |
{ |
|
718 |
return m_segmentSize; |
|
719 |
} |
|
720 |
||
721 |
void |
|
722 |
NscTcpSocketImpl::SetAdvWin (uint32_t window) |
|
723 |
{ |
|
724 |
m_advertisedWindowSize = window; |
|
725 |
} |
|
726 |
||
727 |
uint32_t |
|
728 |
NscTcpSocketImpl::GetAdvWin (void) const |
|
729 |
{ |
|
730 |
return m_advertisedWindowSize; |
|
731 |
} |
|
732 |
||
733 |
void |
|
734 |
NscTcpSocketImpl::SetSSThresh (uint32_t threshold) |
|
735 |
{ |
|
736 |
m_ssThresh = threshold; |
|
737 |
} |
|
738 |
||
739 |
uint32_t |
|
740 |
NscTcpSocketImpl::GetSSThresh (void) const |
|
741 |
{ |
|
742 |
return m_ssThresh; |
|
743 |
} |
|
744 |
||
745 |
void |
|
746 |
NscTcpSocketImpl::SetInitialCwnd (uint32_t cwnd) |
|
747 |
{ |
|
748 |
m_initialCWnd = cwnd; |
|
749 |
} |
|
750 |
||
751 |
uint32_t |
|
752 |
NscTcpSocketImpl::GetInitialCwnd (void) const |
|
753 |
{ |
|
754 |
return m_initialCWnd; |
|
755 |
} |
|
756 |
||
757 |
void |
|
758 |
NscTcpSocketImpl::SetConnTimeout (Time timeout) |
|
759 |
{ |
|
760 |
m_cnTimeout = timeout; |
|
761 |
} |
|
762 |
||
763 |
Time |
|
764 |
NscTcpSocketImpl::GetConnTimeout (void) const |
|
765 |
{ |
|
766 |
return m_cnTimeout; |
|
767 |
} |
|
768 |
||
769 |
void |
|
770 |
NscTcpSocketImpl::SetConnCount (uint32_t count) |
|
771 |
{ |
|
772 |
m_cnCount = count; |
|
773 |
} |
|
774 |
||
775 |
uint32_t |
|
776 |
NscTcpSocketImpl::GetConnCount (void) const |
|
777 |
{ |
|
778 |
return m_cnCount; |
|
779 |
} |
|
780 |
||
781 |
void |
|
782 |
NscTcpSocketImpl::SetDelAckTimeout (Time timeout) |
|
783 |
{ |
|
784 |
m_delAckTimeout = timeout; |
|
785 |
} |
|
786 |
||
787 |
Time |
|
788 |
NscTcpSocketImpl::GetDelAckTimeout (void) const |
|
789 |
{ |
|
790 |
return m_delAckTimeout; |
|
791 |
} |
|
792 |
||
793 |
void |
|
794 |
NscTcpSocketImpl::SetDelAckMaxCount (uint32_t count) |
|
795 |
{ |
|
796 |
m_delAckMaxCount = count; |
|
797 |
} |
|
798 |
||
799 |
uint32_t |
|
800 |
NscTcpSocketImpl::GetDelAckMaxCount (void) const |
|
801 |
{ |
|
802 |
return m_delAckMaxCount; |
|
803 |
} |
|
804 |
||
7619
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
805 |
void |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
806 |
NscTcpSocketImpl::SetTcpNoDelay (bool noDelay) |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
807 |
{ |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
808 |
m_noDelay = noDelay; |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
809 |
} |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
810 |
|
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
811 |
bool |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
812 |
NscTcpSocketImpl::GetTcpNoDelay (void) const |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
813 |
{ |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
814 |
return m_noDelay; |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
815 |
} |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
816 |
|
6694 | 817 |
void |
818 |
NscTcpSocketImpl::SetPersistTimeout (Time timeout) |
|
819 |
{ |
|
820 |
m_persistTimeout = timeout; |
|
821 |
} |
|
822 |
||
823 |
Time |
|
824 |
NscTcpSocketImpl::GetPersistTimeout (void) const |
|
825 |
{ |
|
826 |
return m_persistTimeout; |
|
827 |
} |
|
828 |
||
3578 | 829 |
enum Socket::SocketErrno |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
830 |
NscTcpSocketImpl::GetNativeNs3Errno (int error) const |
3578 | 831 |
{ |
832 |
enum nsc_errno err; |
|
833 |
||
834 |
if (error >= 0) |
|
835 |
{ |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
836 |
return ERROR_NOTERROR; |
3578 | 837 |
} |
838 |
err = (enum nsc_errno) error; |
|
839 |
switch (err) |
|
840 |
{ |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
841 |
case NSC_EADDRINUSE: // fallthrough |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
842 |
case NSC_EADDRNOTAVAIL: return ERROR_AFNOSUPPORT; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
843 |
case NSC_EINPROGRESS: // Altough nsc sockets are nonblocking, we pretend they're not. |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
844 |
case NSC_EAGAIN: return ERROR_AGAIN; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
845 |
case NSC_EISCONN: // fallthrough |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
846 |
case NSC_EALREADY: return ERROR_ISCONN; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
847 |
case NSC_ECONNREFUSED: return ERROR_NOROUTETOHOST; // XXX, better mapping? |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
848 |
case NSC_ECONNRESET: // for no, all of these fall through |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
849 |
case NSC_EHOSTDOWN: |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
850 |
case NSC_ENETUNREACH: |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
851 |
case NSC_EHOSTUNREACH: return ERROR_NOROUTETOHOST; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
852 |
case NSC_EMSGSIZE: return ERROR_MSGSIZE; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
853 |
case NSC_ENOTCONN: return ERROR_NOTCONN; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
854 |
case NSC_ESHUTDOWN: return ERROR_SHUTDOWN; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
855 |
case NSC_ETIMEDOUT: return ERROR_NOTCONN; // XXX - this mapping isn't correct |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
856 |
case NSC_ENOTDIR: // used by eg. sysctl(2). Shouldn't happen normally, |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
857 |
// but is triggered by e.g. show_config(). |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
858 |
case NSC_EUNKNOWN: return ERROR_INVAL; // Catches stacks that 'return -1' without real mapping |
3578 | 859 |
} |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
860 |
NS_ASSERT_MSG (0, "Unknown NSC error"); |
3578 | 861 |
return ERROR_INVAL; |
862 |
} |
|
863 |
||
6448
184a509cc71d
Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6442
diff
changeset
|
864 |
bool |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
865 |
NscTcpSocketImpl::SetAllowBroadcast (bool allowBroadcast) |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
866 |
{ |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
867 |
if (allowBroadcast) |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
868 |
{ |
6448
184a509cc71d
Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6442
diff
changeset
|
869 |
return false; |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
870 |
} |
6448
184a509cc71d
Still Bug 943: fix UdpSocketImpl::GetAllowBroadcast, let Socket::SetAllowBroadcast return a bool indicating success/failure, instead of a fatal error.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6442
diff
changeset
|
871 |
return true; |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
872 |
} |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
873 |
|
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
874 |
bool |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
875 |
NscTcpSocketImpl::GetAllowBroadcast () const |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
876 |
{ |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
877 |
return false; |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
878 |
} |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
879 |
|
7386
2310ed220a61
standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents:
7385
diff
changeset
|
880 |
} // namespace ns3 |