author | Adrian S Tam <adrian.sw.tam@gmail.com> |
Wed, 07 Dec 2011 11:22:10 -0500 | |
changeset 7619 | b4dee6307aa7 |
parent 7600 | 57ba46094a0d |
child 7704 | aef733235832 |
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 |
} |
|
217 |
int |
|
218 |
NscTcpSocketImpl::Bind (const Address &address) |
|
219 |
{ |
|
220 |
NS_LOG_FUNCTION (this<<address); |
|
221 |
if (!InetSocketAddress::IsMatchingType (address)) |
|
222 |
{ |
|
223 |
return ERROR_INVAL; |
|
224 |
} |
|
225 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
|
226 |
Ipv4Address ipv4 = transport.GetIpv4 (); |
|
227 |
uint16_t port = transport.GetPort (); |
|
228 |
if (ipv4 == Ipv4Address::GetAny () && port == 0) |
|
229 |
{ |
|
230 |
m_endPoint = m_tcp->Allocate (); |
|
5888 | 231 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 232 |
} |
233 |
else if (ipv4 == Ipv4Address::GetAny () && port != 0) |
|
234 |
{ |
|
235 |
m_endPoint = m_tcp->Allocate (port); |
|
5888 | 236 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 237 |
} |
238 |
else if (ipv4 != Ipv4Address::GetAny () && port == 0) |
|
239 |
{ |
|
240 |
m_endPoint = m_tcp->Allocate (ipv4); |
|
5888 | 241 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 242 |
} |
243 |
else if (ipv4 != Ipv4Address::GetAny () && port != 0) |
|
244 |
{ |
|
245 |
m_endPoint = m_tcp->Allocate (ipv4, port); |
|
5888 | 246 |
NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint); |
3578 | 247 |
} |
248 |
||
249 |
m_localPort = port; |
|
250 |
return FinishBind (); |
|
251 |
} |
|
252 |
||
253 |
int |
|
254 |
NscTcpSocketImpl::ShutdownSend (void) |
|
255 |
{ |
|
256 |
NS_LOG_FUNCTION_NOARGS (); |
|
257 |
m_shutdownSend = true; |
|
258 |
return 0; |
|
259 |
} |
|
260 |
int |
|
261 |
NscTcpSocketImpl::ShutdownRecv (void) |
|
262 |
{ |
|
263 |
NS_LOG_FUNCTION_NOARGS (); |
|
4491
893d48fcf7f3
bug 535: UDP/TCP ShutdownRecv incorrect
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3869
diff
changeset
|
264 |
m_shutdownRecv = true; |
3578 | 265 |
return 0; |
266 |
} |
|
267 |
||
268 |
int |
|
269 |
NscTcpSocketImpl::Close (void) |
|
270 |
{ |
|
271 |
NS_LOG_FUNCTION (this << m_state); |
|
272 |
||
273 |
if (m_state == CLOSED) |
|
274 |
{ |
|
275 |
return -1; |
|
276 |
} |
|
277 |
if (!m_txBuffer.empty ()) |
|
278 |
{ // App close with pending data must wait until all data transmitted |
|
279 |
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
|
280 |
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
|
281 |
" deferring close, state " << m_state); |
3578 | 282 |
return 0; |
283 |
} |
|
284 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
285 |
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
|
286 |
m_nscTcpSocket->disconnect (); |
3578 | 287 |
m_state = CLOSED; |
288 |
ShutdownSend (); |
|
289 |
return 0; |
|
290 |
} |
|
291 |
||
292 |
int |
|
293 |
NscTcpSocketImpl::Connect (const Address & address) |
|
294 |
{ |
|
295 |
NS_LOG_FUNCTION (this << address); |
|
296 |
if (m_endPoint == 0) |
|
297 |
{ |
|
298 |
if (Bind () == -1) |
|
299 |
{ |
|
300 |
NS_ASSERT (m_endPoint == 0); |
|
301 |
return -1; |
|
302 |
} |
|
303 |
NS_ASSERT (m_endPoint != 0); |
|
304 |
} |
|
305 |
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address); |
|
306 |
m_remoteAddress = transport.GetIpv4 (); |
|
307 |
m_remotePort = transport.GetPort (); |
|
308 |
||
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
309 |
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
|
310 |
m_remoteAddress.Print (ss); |
3711
fed597b0583e
nsc: avoid unecessary use of posix headers
Florian Westphal <fw@strlen.de>
parents:
3635
diff
changeset
|
311 |
std::string ipstring = ss.str (); |
3578 | 312 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
313 |
m_nscTcpSocket->connect (ipstring.c_str (), m_remotePort); |
3578 | 314 |
m_state = SYN_SENT; |
315 |
return 0; |
|
316 |
} |
|
317 |
||
318 |
int |
|
319 |
NscTcpSocketImpl::Send (const Ptr<Packet> p, uint32_t flags) |
|
320 |
{ |
|
321 |
NS_LOG_FUNCTION (this << p); |
|
322 |
||
323 |
NS_ASSERT (p->GetSize () > 0); |
|
324 |
if (m_state == ESTABLISHED || m_state == SYN_SENT || m_state == CLOSE_WAIT) |
|
325 |
{ |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
326 |
if (p->GetSize () > GetTxAvailable ()) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
327 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
328 |
m_errno = ERROR_MSGSIZE; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
329 |
return -1; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
330 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
331 |
|
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
332 |
uint32_t sent = p->GetSize (); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
333 |
if (m_state == ESTABLISHED) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
334 |
{ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
335 |
m_txBuffer.push (p); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
336 |
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
|
337 |
SendPendingData (); |
7176
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 |
else |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
340 |
{ // 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
|
341 |
m_txBuffer.push (p); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
342 |
m_txBufferSize += sent; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
343 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
344 |
return sent; |
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 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
348 |
m_errno = ERROR_NOTCONN; |
3578 | 349 |
return -1; |
350 |
} |
|
351 |
} |
|
352 |
||
353 |
int |
|
354 |
NscTcpSocketImpl::SendTo (Ptr<Packet> p, uint32_t flags, const Address &address) |
|
355 |
{ |
|
356 |
NS_LOG_FUNCTION (this << address << p); |
|
357 |
if (!m_connected) |
|
358 |
{ |
|
359 |
m_errno = ERROR_NOTCONN; |
|
360 |
return -1; |
|
361 |
} |
|
362 |
else |
|
363 |
{ |
|
364 |
return Send (p, flags); //drop the address according to BSD manpages |
|
365 |
} |
|
366 |
} |
|
367 |
||
368 |
uint32_t |
|
369 |
NscTcpSocketImpl::GetTxAvailable (void) const |
|
370 |
{ |
|
371 |
NS_LOG_FUNCTION_NOARGS (); |
|
372 |
if (m_txBufferSize != 0) |
|
373 |
{ |
|
374 |
NS_ASSERT (m_txBufferSize <= m_sndBufSize); |
|
375 |
return m_sndBufSize - m_txBufferSize; |
|
376 |
} |
|
377 |
else |
|
378 |
{ |
|
379 |
return m_sndBufSize; |
|
380 |
} |
|
381 |
} |
|
382 |
||
383 |
int |
|
3772
f0d8608ab155
Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents:
3711
diff
changeset
|
384 |
NscTcpSocketImpl::Listen (void) |
3578 | 385 |
{ |
3772
f0d8608ab155
Remove queue limit from listen
Craig Dowell <craigdo@ee.washington.edu>
parents:
3711
diff
changeset
|
386 |
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
|
387 |
m_nscTcpSocket->listen (m_localPort); |
3578 | 388 |
m_state = LISTEN; |
389 |
return 0; |
|
390 |
} |
|
391 |
||
392 |
||
393 |
void |
|
394 |
NscTcpSocketImpl::NSCWakeup () |
|
395 |
{ |
|
396 |
switch (m_state) { |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
397 |
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
|
398 |
if (!m_nscTcpSocket->is_connected ()) |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
399 |
break; |
3578 | 400 |
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
|
401 |
Simulator::ScheduleNow (&NscTcpSocketImpl::ConnectionSucceeded, this); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
402 |
// fall through to schedule read/write events |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
403 |
case ESTABLISHED: |
3578 | 404 |
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
|
405 |
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
|
406 |
Simulator::ScheduleNow (&NscTcpSocketImpl::ReadPendingData, this); |
3578 | 407 |
break; |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
408 |
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
|
409 |
Simulator::ScheduleNow (&NscTcpSocketImpl::Accept, this); |
3578 | 410 |
break; |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
411 |
case CLOSED: break; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
412 |
default: |
3578 | 413 |
NS_LOG_DEBUG (this << " invalid state: " << m_state); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
414 |
} |
3578 | 415 |
} |
416 |
||
417 |
Ptr<Packet> |
|
418 |
NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags) |
|
419 |
{ |
|
420 |
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
|
421 |
if (m_deliveryQueue.empty () ) |
3578 | 422 |
{ |
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
|
423 |
m_errno = ERROR_AGAIN; |
3578 | 424 |
return 0; |
425 |
} |
|
426 |
Ptr<Packet> p = m_deliveryQueue.front (); |
|
427 |
if (p->GetSize () <= maxSize) |
|
428 |
{ |
|
429 |
m_deliveryQueue.pop (); |
|
430 |
m_rxAvailable -= p->GetSize (); |
|
431 |
} |
|
432 |
else |
|
433 |
{ |
|
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
|
434 |
m_errno = ERROR_AGAIN; |
3578 | 435 |
p = 0; |
436 |
} |
|
437 |
return p; |
|
438 |
} |
|
439 |
||
440 |
Ptr<Packet> |
|
441 |
NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags, |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
442 |
Address &fromAddress) |
3578 | 443 |
{ |
444 |
NS_LOG_FUNCTION (this << maxSize << flags); |
|
445 |
Ptr<Packet> packet = Recv (maxSize, flags); |
|
446 |
if (packet != 0) |
|
447 |
{ |
|
448 |
SocketAddressTag tag; |
|
449 |
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
|
450 |
found = packet->PeekPacketTag (tag); |
3578 | 451 |
NS_ASSERT (found); |
7257
1b1f34b88a4a
NSC unused variables
John Abraham<john.abraham@gatech.edu>
parents:
7256
diff
changeset
|
452 |
// cast found to void, to suppress 'found' set but not used |
1b1f34b88a4a
NSC unused variables
John Abraham<john.abraham@gatech.edu>
parents:
7256
diff
changeset
|
453 |
// compiler warning in optimized builds |
1b1f34b88a4a
NSC unused variables
John Abraham<john.abraham@gatech.edu>
parents:
7256
diff
changeset
|
454 |
(void) found; |
3578 | 455 |
fromAddress = tag.GetAddress (); |
456 |
} |
|
457 |
return packet; |
|
458 |
} |
|
459 |
||
3778
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
460 |
int |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
461 |
NscTcpSocketImpl::GetSockName (Address &address) const |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
462 |
{ |
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
463 |
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
|
464 |
address = InetSocketAddress (m_localAddress, m_localPort); |
3778
78c4c41557f3
Liu's GetSockName patch
Craig Dowell <craigdo@ee.washington.edu>
parents:
3772
diff
changeset
|
465 |
return 0; |
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 |
|
3578 | 468 |
uint32_t |
469 |
NscTcpSocketImpl::GetRxAvailable (void) const |
|
470 |
{ |
|
471 |
NS_LOG_FUNCTION_NOARGS (); |
|
472 |
// We separately maintain this state to avoid walking the queue |
|
473 |
// every time this might be called |
|
474 |
return m_rxAvailable; |
|
475 |
} |
|
476 |
||
477 |
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
|
478 |
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
|
479 |
Ptr<Ipv4Interface> incomingInterface) |
3578 | 480 |
{ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
481 |
NSCWakeup (); |
3578 | 482 |
} |
483 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
484 |
void NscTcpSocketImpl::CompleteFork (void) |
3578 | 485 |
{ |
486 |
// The address pairs (m_localAddress, m_localPort, m_remoteAddress, m_remotePort) |
|
487 |
// are bogus, but this isn't important at the moment, because |
|
488 |
// address <-> Socket handling is done by NSC internally. |
|
489 |
// We only need to add the new ns-3 socket to the list of sockets, so |
|
490 |
// 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
|
491 |
struct sockaddr_in sin; |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
492 |
size_t sin_len = sizeof(sin); |
3578 | 493 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
m_peerAddress = InetSocketAddress (m_remoteAddress, m_remotePort); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
498 |
} |
3578 | 499 |
|
500 |
m_endPoint = m_tcp->Allocate (); |
|
501 |
||
502 |
//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
|
503 |
NS_ASSERT (m_state == LISTEN); |
3578 | 504 |
m_state = ESTABLISHED; |
505 |
||
3869
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
506 |
sin_len = sizeof(sin); |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
507 |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
508 |
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
|
509 |
m_localAddress = m_localAddress.Deserialize ((const uint8_t*) &sin.sin_addr); |
3578 | 510 |
|
511 |
NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " accepted connection from " |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
512 |
<< m_remoteAddress << ":" << m_remotePort |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
513 |
<< " to " << m_localAddress << ":" << m_localPort); |
3578 | 514 |
//equivalent to FinishBind |
515 |
m_endPoint->SetRxCallback (MakeCallback (&NscTcpSocketImpl::ForwardUp, Ptr<NscTcpSocketImpl>(this))); |
|
516 |
m_endPoint->SetDestroyCallback (MakeCallback (&NscTcpSocketImpl::Destroy, Ptr<NscTcpSocketImpl>(this))); |
|
517 |
||
518 |
NotifyNewConnectionCreated (this, m_peerAddress); |
|
519 |
} |
|
520 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
521 |
void NscTcpSocketImpl::ConnectionSucceeded () |
3578 | 522 |
{ // We would preferred to have scheduled an event directly to |
523 |
// NotifyConnectionSucceeded, but (sigh) these are protected |
|
524 |
// 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
|
525 |
struct sockaddr_in sin; |
0edba1e055aa
nsc-tcp-socket-impl: use new nsc getsockname/getpeername interface.
Florian Westphal <fw@strlen.de>
parents:
3780
diff
changeset
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
m_localPort = ntohs (sin.sin_port); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
530 |
} |
3578 | 531 |
|
532 |
NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to " |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
533 |
<< m_remoteAddress << ":" << m_remotePort |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
534 |
<< " 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
|
535 |
NotifyConnectionSucceeded (); |
3578 | 536 |
} |
537 |
||
538 |
||
539 |
bool NscTcpSocketImpl::Accept (void) |
|
540 |
{ |
|
541 |
if (m_state == CLOSED) |
|
542 |
{ // Happens if application closes listening socket after Accept() was scheduled. |
|
543 |
return false; |
|
544 |
} |
|
545 |
NS_ASSERT (m_state == LISTEN); |
|
546 |
||
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
547 |
if (!m_nscTcpSocket->is_listening ()) |
3578 | 548 |
{ |
549 |
return false; |
|
550 |
} |
|
551 |
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
|
552 |
int res = m_nscTcpSocket->accept (&newsock); |
3578 | 553 |
if (res != 0) |
554 |
{ |
|
555 |
return false; |
|
556 |
} |
|
557 |
// We could obtain a fromAddress using getpeername, but we've already |
|
558 |
// finished the tcp handshake here, i.e. this is a new connection |
|
559 |
// and not a connection request. |
|
560 |
// if (!NotifyConnectionRequest(fromAddress)) |
|
561 |
// return true; |
|
562 |
||
563 |
// Clone the socket |
|
564 |
Ptr<NscTcpSocketImpl> newSock = Copy (); |
|
565 |
newSock->m_nscTcpSocket = newsock; |
|
566 |
NS_LOG_LOGIC ("Cloned a NscTcpSocketImpl " << newSock); |
|
567 |
||
568 |
Simulator::ScheduleNow (&NscTcpSocketImpl::CompleteFork, newSock); |
|
569 |
return true; |
|
570 |
} |
|
571 |
||
572 |
bool NscTcpSocketImpl::ReadPendingData (void) |
|
573 |
{ |
|
574 |
if (m_state != ESTABLISHED) |
|
575 |
{ |
|
576 |
return false; |
|
577 |
} |
|
578 |
int len, err; |
|
579 |
uint8_t buffer[8192]; |
|
580 |
len = sizeof(buffer); |
|
581 |
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
|
582 |
err = m_nscTcpSocket->read_data (buffer, &len); |
3578 | 583 |
if (err == 0 && len == 0) |
584 |
{ |
|
585 |
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
|
586 |
m_state = CLOSE_WAIT; |
3578 | 587 |
return false; |
588 |
} |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
589 |
m_errno = GetNativeNs3Errno (err); |
3578 | 590 |
switch (m_errno) |
591 |
{ |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
592 |
case ERROR_NOTERROR: break; // some data was sent |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
593 |
case ERROR_AGAIN: return false; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
594 |
default: |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
595 |
NS_LOG_WARN ("Error (" << err << ") " << |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
596 |
"during read_data, ns-3 errno set to" << m_errno); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
597 |
m_state = CLOSED; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
598 |
return false; |
3578 | 599 |
} |
600 |
||
601 |
Ptr<Packet> p = Create<Packet> (buffer, len); |
|
602 |
||
603 |
SocketAddressTag tag; |
|
604 |
||
605 |
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
|
606 |
p->AddPacketTag (tag); |
3578 | 607 |
m_deliveryQueue.push (p); |
608 |
m_rxAvailable += p->GetSize (); |
|
609 |
||
610 |
NotifyDataRecv (); |
|
611 |
return true; |
|
612 |
} |
|
613 |
||
614 |
bool NscTcpSocketImpl::SendPendingData (void) |
|
615 |
{ |
|
616 |
NS_LOG_FUNCTION (this); |
|
617 |
NS_LOG_LOGIC ("ENTERING SendPendingData"); |
|
618 |
||
619 |
if (m_txBuffer.empty ()) |
|
620 |
{ |
|
621 |
return false; |
|
622 |
} |
|
623 |
||
624 |
int ret; |
|
625 |
size_t size, written = 0; |
|
626 |
||
627 |
do { |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
628 |
NS_ASSERT (!m_txBuffer.empty ()); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
629 |
Ptr<Packet> &p = m_txBuffer.front (); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
630 |
size = p->GetSize (); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
631 |
NS_ASSERT (size > 0); |
3578 | 632 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
633 |
m_errno = ERROR_NOTERROR; |
6549
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
634 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
635 |
uint8_t *buf = new uint8_t[size]; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
636 |
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
|
637 |
ret = m_nscTcpSocket->send_data ((const char *)buf, size); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
638 |
delete[] buf; |
6549
487146fc889e
get rid of about a zillion PeekData
Craig Dowell <craigdo@ee.washington.edu>
parents:
6448
diff
changeset
|
639 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
640 |
if (ret <= 0) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
641 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
642 |
break; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
643 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
644 |
written += ret; |
3578 | 645 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
646 |
NS_ASSERT (m_txBufferSize >= (size_t)ret); |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
647 |
m_txBufferSize -= ret; |
3578 | 648 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
649 |
if ((size_t)ret < size) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
650 |
{ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
651 |
p->RemoveAtStart (ret); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
652 |
break; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
653 |
} |
3578 | 654 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
655 |
m_txBuffer.pop (); |
3578 | 656 |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
657 |
if (m_txBuffer.empty ()) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
658 |
{ |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
659 |
if (m_closeOnEmpty) |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
660 |
{ |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
661 |
m_nscTcpSocket->disconnect (); |
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
662 |
m_state = CLOSED; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
663 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
664 |
break; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
665 |
} |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
666 |
} while ((size_t) ret == size); |
3578 | 667 |
|
668 |
if (written > 0) |
|
669 |
{ |
|
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
670 |
Simulator::ScheduleNow (&NscTcpSocketImpl::NotifyDataSent, this, ret); |
3578 | 671 |
return true; |
672 |
} |
|
673 |
return false; |
|
674 |
} |
|
675 |
||
676 |
Ptr<NscTcpSocketImpl> NscTcpSocketImpl::Copy () |
|
677 |
{ |
|
678 |
return CopyObject<NscTcpSocketImpl> (this); |
|
679 |
} |
|
680 |
||
681 |
void |
|
682 |
NscTcpSocketImpl::SetSndBufSize (uint32_t size) |
|
683 |
{ |
|
684 |
m_sndBufSize = size; |
|
685 |
} |
|
686 |
||
687 |
uint32_t |
|
688 |
NscTcpSocketImpl::GetSndBufSize (void) const |
|
689 |
{ |
|
690 |
return m_sndBufSize; |
|
691 |
} |
|
692 |
||
693 |
void |
|
694 |
NscTcpSocketImpl::SetRcvBufSize (uint32_t size) |
|
695 |
{ |
|
696 |
m_rcvBufSize = size; |
|
697 |
} |
|
698 |
||
699 |
uint32_t |
|
700 |
NscTcpSocketImpl::GetRcvBufSize (void) const |
|
701 |
{ |
|
702 |
return m_rcvBufSize; |
|
703 |
} |
|
704 |
||
705 |
void |
|
706 |
NscTcpSocketImpl::SetSegSize (uint32_t size) |
|
707 |
{ |
|
708 |
m_segmentSize = size; |
|
709 |
} |
|
710 |
||
711 |
uint32_t |
|
712 |
NscTcpSocketImpl::GetSegSize (void) const |
|
713 |
{ |
|
714 |
return m_segmentSize; |
|
715 |
} |
|
716 |
||
717 |
void |
|
718 |
NscTcpSocketImpl::SetAdvWin (uint32_t window) |
|
719 |
{ |
|
720 |
m_advertisedWindowSize = window; |
|
721 |
} |
|
722 |
||
723 |
uint32_t |
|
724 |
NscTcpSocketImpl::GetAdvWin (void) const |
|
725 |
{ |
|
726 |
return m_advertisedWindowSize; |
|
727 |
} |
|
728 |
||
729 |
void |
|
730 |
NscTcpSocketImpl::SetSSThresh (uint32_t threshold) |
|
731 |
{ |
|
732 |
m_ssThresh = threshold; |
|
733 |
} |
|
734 |
||
735 |
uint32_t |
|
736 |
NscTcpSocketImpl::GetSSThresh (void) const |
|
737 |
{ |
|
738 |
return m_ssThresh; |
|
739 |
} |
|
740 |
||
741 |
void |
|
742 |
NscTcpSocketImpl::SetInitialCwnd (uint32_t cwnd) |
|
743 |
{ |
|
744 |
m_initialCWnd = cwnd; |
|
745 |
} |
|
746 |
||
747 |
uint32_t |
|
748 |
NscTcpSocketImpl::GetInitialCwnd (void) const |
|
749 |
{ |
|
750 |
return m_initialCWnd; |
|
751 |
} |
|
752 |
||
753 |
void |
|
754 |
NscTcpSocketImpl::SetConnTimeout (Time timeout) |
|
755 |
{ |
|
756 |
m_cnTimeout = timeout; |
|
757 |
} |
|
758 |
||
759 |
Time |
|
760 |
NscTcpSocketImpl::GetConnTimeout (void) const |
|
761 |
{ |
|
762 |
return m_cnTimeout; |
|
763 |
} |
|
764 |
||
765 |
void |
|
766 |
NscTcpSocketImpl::SetConnCount (uint32_t count) |
|
767 |
{ |
|
768 |
m_cnCount = count; |
|
769 |
} |
|
770 |
||
771 |
uint32_t |
|
772 |
NscTcpSocketImpl::GetConnCount (void) const |
|
773 |
{ |
|
774 |
return m_cnCount; |
|
775 |
} |
|
776 |
||
777 |
void |
|
778 |
NscTcpSocketImpl::SetDelAckTimeout (Time timeout) |
|
779 |
{ |
|
780 |
m_delAckTimeout = timeout; |
|
781 |
} |
|
782 |
||
783 |
Time |
|
784 |
NscTcpSocketImpl::GetDelAckTimeout (void) const |
|
785 |
{ |
|
786 |
return m_delAckTimeout; |
|
787 |
} |
|
788 |
||
789 |
void |
|
790 |
NscTcpSocketImpl::SetDelAckMaxCount (uint32_t count) |
|
791 |
{ |
|
792 |
m_delAckMaxCount = count; |
|
793 |
} |
|
794 |
||
795 |
uint32_t |
|
796 |
NscTcpSocketImpl::GetDelAckMaxCount (void) const |
|
797 |
{ |
|
798 |
return m_delAckMaxCount; |
|
799 |
} |
|
800 |
||
7619
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
801 |
void |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
802 |
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
|
803 |
{ |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
804 |
m_noDelay = noDelay; |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
805 |
} |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
806 |
|
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
807 |
bool |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
808 |
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
|
809 |
{ |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
810 |
return m_noDelay; |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
811 |
} |
b4dee6307aa7
Nagle's algorithm in TCP (closes bug 1039)
Adrian S Tam <adrian.sw.tam@gmail.com>
parents:
7600
diff
changeset
|
812 |
|
6694 | 813 |
void |
814 |
NscTcpSocketImpl::SetPersistTimeout (Time timeout) |
|
815 |
{ |
|
816 |
m_persistTimeout = timeout; |
|
817 |
} |
|
818 |
||
819 |
Time |
|
820 |
NscTcpSocketImpl::GetPersistTimeout (void) const |
|
821 |
{ |
|
822 |
return m_persistTimeout; |
|
823 |
} |
|
824 |
||
3578 | 825 |
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
|
826 |
NscTcpSocketImpl::GetNativeNs3Errno (int error) const |
3578 | 827 |
{ |
828 |
enum nsc_errno err; |
|
829 |
||
830 |
if (error >= 0) |
|
831 |
{ |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
832 |
return ERROR_NOTERROR; |
3578 | 833 |
} |
834 |
err = (enum nsc_errno) error; |
|
835 |
switch (err) |
|
836 |
{ |
|
7176
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
837 |
case NSC_EADDRINUSE: // fallthrough |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
838 |
case NSC_EADDRNOTAVAIL: return ERROR_AFNOSUPPORT; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
839 |
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
|
840 |
case NSC_EAGAIN: return ERROR_AGAIN; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
841 |
case NSC_EISCONN: // fallthrough |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
842 |
case NSC_EALREADY: return ERROR_ISCONN; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
843 |
case NSC_ECONNREFUSED: return ERROR_NOROUTETOHOST; // XXX, better mapping? |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
844 |
case NSC_ECONNRESET: // for no, all of these fall through |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
845 |
case NSC_EHOSTDOWN: |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
846 |
case NSC_ENETUNREACH: |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
847 |
case NSC_EHOSTUNREACH: return ERROR_NOROUTETOHOST; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
848 |
case NSC_EMSGSIZE: return ERROR_MSGSIZE; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
849 |
case NSC_ENOTCONN: return ERROR_NOTCONN; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
850 |
case NSC_ESHUTDOWN: return ERROR_SHUTDOWN; |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
851 |
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
|
852 |
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
|
853 |
// but is triggered by e.g. show_config(). |
9f2663992e99
internet coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents:
6834
diff
changeset
|
854 |
case NSC_EUNKNOWN: return ERROR_INVAL; // Catches stacks that 'return -1' without real mapping |
3578 | 855 |
} |
7256
b04ba6772f8c
rerun check-style.py at default level to enforce space after function name
Tom Henderson <tomh@tomh.org>
parents:
7176
diff
changeset
|
856 |
NS_ASSERT_MSG (0, "Unknown NSC error"); |
3578 | 857 |
return ERROR_INVAL; |
858 |
} |
|
859 |
||
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
|
860 |
bool |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
861 |
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
|
862 |
{ |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
863 |
if (allowBroadcast) |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
864 |
{ |
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
|
865 |
return false; |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
866 |
} |
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
|
867 |
return true; |
6437
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
868 |
} |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
869 |
|
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
870 |
bool |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
871 |
NscTcpSocketImpl::GetAllowBroadcast () const |
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 |
return false; |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
874 |
} |
c11291f51d57
Bug 943 - Add a SO_BROADCAST socket option
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
6319
diff
changeset
|
875 |
|
7386
2310ed220a61
standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents:
7385
diff
changeset
|
876 |
} // namespace ns3 |