A Discrete-Event Network Simulator
API
nsc-tcp-socket-impl.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 
20 #define NS_LOG_APPEND_CONTEXT \
21  if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; }
22 
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 
38 // for ntohs().
39 #include <arpa/inet.h>
40 #include <netinet/in.h>
41 #include "sim_interface.h"
42 
43 #include "sim_errno.h"
44 
45 
46 namespace ns3 {
47 
48 NS_LOG_COMPONENT_DEFINE ("NscTcpSocketImpl");
49 
50 NS_OBJECT_ENSURE_REGISTERED (NscTcpSocketImpl);
51 
52 TypeId
54 {
55  static TypeId tid = TypeId ("ns3::NscTcpSocketImpl")
56  .SetParent<TcpSocket> ()
57  .SetGroupName ("Internet")
58  .AddTraceSource ("CongestionWindow",
59  "The TCP connection's congestion window",
61  "ns3::TracedValueCallback::Uint32")
62  .AddTraceSource ("SlowStartThreshold",
63  "TCP slow start threshold (bytes)",
65  "ns3::TracedValueCallback::Uint32")
66  .AddTraceSource ("State",
67  "TCP state",
69  "ns3::TcpStatesTracedValueCallback")
70  ;
71  return tid;
72 }
73 
75  : m_endPoint (0),
76  m_node (0),
77  m_tcp (0),
78  m_localAddress (Ipv4Address::GetZero ()),
79  m_localPort (0),
80  m_peerAddress ("0.0.0.0", 0),
81  m_errno (ERROR_NOTERROR),
82  m_shutdownSend (false),
83  m_shutdownRecv (false),
84  m_connected (false),
85  m_state (CLOSED),
86  m_closeOnEmpty (false),
87  m_txBufferSize (0),
88  m_lastMeasuredRtt (Seconds (0.0))
89 {
90  NS_LOG_FUNCTION (this);
91 }
92 
94  : TcpSocket (sock), //copy the base class callbacks
95  m_delAckMaxCount (sock.m_delAckMaxCount),
96  m_delAckTimeout (sock.m_delAckTimeout),
97  m_noDelay (sock.m_noDelay),
98  m_endPoint (0),
99  m_node (sock.m_node),
100  m_tcp (sock.m_tcp),
101  m_remoteAddress (sock.m_remoteAddress),
102  m_remotePort (sock.m_remotePort),
103  m_localAddress (sock.m_localAddress),
104  m_localPort (sock.m_localPort),
105  m_peerAddress (sock.m_peerAddress),
106  m_errno (sock.m_errno),
107  m_shutdownSend (sock.m_shutdownSend),
108  m_shutdownRecv (sock.m_shutdownRecv),
109  m_connected (sock.m_connected),
110  m_state (sock.m_state),
111  m_closeOnEmpty (sock.m_closeOnEmpty),
112  m_txBufferSize (sock.m_txBufferSize),
113  m_segmentSize (sock.m_segmentSize),
114  m_rxWindowSize (sock.m_rxWindowSize),
115  m_advertisedWindowSize (sock.m_advertisedWindowSize),
116  m_cWnd (sock.m_cWnd),
117  m_ssThresh (sock.m_ssThresh),
118  m_initialCWnd (sock.m_initialCWnd),
119  m_initialSsThresh (sock.m_initialSsThresh),
120  m_lastMeasuredRtt (Seconds (0.0)),
121  m_cnTimeout (sock.m_cnTimeout),
122  m_cnCount (sock.m_cnCount),
123  m_rxAvailable (0),
124  m_nscTcpSocket (0),
125  m_sndBufSize (sock.m_sndBufSize)
126 {
128  NS_LOG_LOGIC ("Invoked the copy constructor");
129  //copy the pending data if necessary
130  if(!sock.m_txBuffer.empty () )
131  {
132  m_txBuffer = sock.m_txBuffer;
133  }
134  //can't "copy" the endpoint just yes, must do this when we know the peer info
135  //too; this is in SYN_ACK_TX
136 }
137 
139 {
140  NS_LOG_FUNCTION (this);
141  m_node = 0;
142  if (m_endPoint != 0)
143  {
144  NS_ASSERT (m_tcp != 0);
153  NS_ASSERT (m_endPoint != 0);
154  m_tcp->DeAllocate (m_endPoint);
155  NS_ASSERT (m_endPoint == 0);
156  }
157  m_tcp = 0;
158 }
159 
160 void
162 {
163  m_node = node;
164  // Initialize some variables
168 }
169 
170 void
172 {
173  m_nscTcpSocket = tcp->m_nscStack->new_tcp_socket ();
174  m_tcp = tcp;
175 }
176 
177 
180 {
182  return m_errno;
183 }
184 
187 {
188  return NS3_SOCK_STREAM;
189 }
190 
191 Ptr<Node>
193 {
195  return m_node;
196 }
197 
198 void
200 {
202  m_node = 0;
203  m_endPoint = 0;
204  m_tcp = 0;
205 }
206 int
208 {
210  if (m_endPoint == 0)
211  {
212  return -1;
213  }
218  return 0;
219 }
220 
221 int
223 {
225  m_endPoint = m_tcp->Allocate ();
226  return FinishBind ();
227 }
228 int
230 {
231  NS_LOG_LOGIC ("NscTcpSocketImpl: ERROR_AFNOSUPPORT - Bind6 not supported");
233  return (-1);
234 }
235 int
237 {
238  NS_LOG_FUNCTION (this<<address);
239  if (!InetSocketAddress::IsMatchingType (address))
240  {
241  return ERROR_INVAL;
242  }
244  Ipv4Address ipv4 = transport.GetIpv4 ();
245  uint16_t port = transport.GetPort ();
246  if (ipv4 == Ipv4Address::GetAny () && port == 0)
247  {
248  m_endPoint = m_tcp->Allocate ();
249  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
250  }
251  else if (ipv4 == Ipv4Address::GetAny () && port != 0)
252  {
253  m_endPoint = m_tcp->Allocate (port);
254  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
255  }
256  else if (ipv4 != Ipv4Address::GetAny () && port == 0)
257  {
258  m_endPoint = m_tcp->Allocate (ipv4);
259  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
260  }
261  else if (ipv4 != Ipv4Address::GetAny () && port != 0)
262  {
263  m_endPoint = m_tcp->Allocate (ipv4, port);
264  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
265  }
266 
267  m_localPort = port;
268  return FinishBind ();
269 }
270 
271 int
273 {
275  m_shutdownSend = true;
276  return 0;
277 }
278 int
280 {
282  m_shutdownRecv = true;
283  return 0;
284 }
285 
286 int
288 {
289  NS_LOG_FUNCTION (this << m_state);
290 
291  if (m_state == CLOSED)
292  {
293  return -1;
294  }
295  if (!m_txBuffer.empty ())
296  { // App close with pending data must wait until all data transmitted
297  m_closeOnEmpty = true;
298  NS_LOG_LOGIC ("Socket " << this <<
299  " deferring close, state " << m_state);
300  return 0;
301  }
302 
303  NS_LOG_LOGIC ("NscTcp socket " << this << " calling disconnect(); moving to CLOSED");
305  m_state = CLOSED;
306  ShutdownSend ();
307  return 0;
308 }
309 
310 int
312 {
313  NS_LOG_FUNCTION (this << address);
314  if (m_endPoint == 0)
315  {
316  if (Bind () == -1)
317  {
318  NS_ASSERT (m_endPoint == 0);
319  return -1;
320  }
321  NS_ASSERT (m_endPoint != 0);
322  }
324  m_remoteAddress = transport.GetIpv4 ();
325  m_remotePort = transport.GetPort ();
326 
327  std::ostringstream ss;
328  m_remoteAddress.Print (ss);
329  std::string ipstring = ss.str ();
330 
331  m_nscTcpSocket->connect (ipstring.c_str (), m_remotePort);
332  m_state = SYN_SENT;
333  return 0;
334 }
335 
336 int
337 NscTcpSocketImpl::Send (const Ptr<Packet> p, uint32_t flags)
338 {
339  NS_LOG_FUNCTION (this << p);
340 
341  NS_ASSERT (p->GetSize () > 0);
343  {
344  if (p->GetSize () > GetTxAvailable ())
345  {
347  return -1;
348  }
349 
350  uint32_t sent = p->GetSize ();
351  if (m_state == ESTABLISHED)
352  {
353  m_txBuffer.push (p);
354  m_txBufferSize += sent;
355  SendPendingData ();
356  }
357  else
358  { // SYN_SET -- Queue Data
359  m_txBuffer.push (p);
360  m_txBufferSize += sent;
361  }
362  return sent;
363  }
364  else
365  {
367  return -1;
368  }
369 }
370 
371 int
373 {
374  NS_LOG_FUNCTION (this << address << p);
375  if (!m_connected)
376  {
378  return -1;
379  }
380  else
381  {
382  return Send (p, flags); //drop the address according to BSD manpages
383  }
384 }
385 
386 uint32_t
388 {
390  if (m_txBufferSize != 0)
391  {
393  return m_sndBufSize - m_txBufferSize;
394  }
395  else
396  {
397  return m_sndBufSize;
398  }
399 }
400 
401 int
403 {
404  NS_LOG_FUNCTION (this);
406  m_state = LISTEN;
407  return 0;
408 }
409 
410 
411 void
413 {
414  switch (m_state) {
415  case SYN_SENT:
416  if (!m_nscTcpSocket->is_connected ())
417  break;
420  // fall through to schedule read/write events
421  case ESTABLISHED:
422  if (!m_txBuffer.empty ())
425  break;
426  case LISTEN:
428  break;
429  case CLOSED: break;
430  default:
431  NS_LOG_DEBUG (this << " invalid state: " << m_state);
432  }
433 }
434 
436 NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
437 {
439  if (m_deliveryQueue.empty () )
440  {
442  return 0;
443  }
444  Ptr<Packet> p = m_deliveryQueue.front ();
445  if (p->GetSize () <= maxSize)
446  {
447  m_deliveryQueue.pop ();
448  m_rxAvailable -= p->GetSize ();
449  }
450  else
451  {
453  p = 0;
454  }
455  return p;
456 }
457 
459 NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
460  Address &fromAddress)
461 {
462  NS_LOG_FUNCTION (this << maxSize << flags);
463  Ptr<Packet> packet = Recv (maxSize, flags);
464  if (packet != 0)
465  {
466  SocketAddressTag tag;
467  bool found;
468  found = packet->PeekPacketTag (tag);
469  NS_ASSERT (found);
470  fromAddress = tag.GetAddress ();
471  }
472  return packet;
473 }
474 
475 int
477 {
480  return 0;
481 }
482 
483 uint32_t
485 {
487  // We separately maintain this state to avoid walking the queue
488  // every time this might be called
489  return m_rxAvailable;
490 }
491 
492 void
494  Ptr<Ipv4Interface> incomingInterface)
495 {
496  NSCWakeup ();
497 }
498 
500 {
501  // The address pairs (m_localAddress, m_localPort, m_remoteAddress, m_remotePort)
502  // are bogus, but this isn't important at the moment, because
503  // address <-> Socket handling is done by NSC internally.
504  // We only need to add the new ns-3 socket to the list of sockets, so
505  // we use plain Allocate() instead of Allocate(m_localAddress, ... )
506  struct sockaddr_in sin;
507  size_t sin_len = sizeof(sin);
508 
509  if (0 == m_nscTcpSocket->getpeername ((struct sockaddr*) &sin, &sin_len)) {
510  m_remotePort = ntohs (sin.sin_port);
511  m_remoteAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
513  }
514 
515  m_endPoint = m_tcp->Allocate ();
516 
517  //the cloned socket with be in listen state, so manually change state
518  NS_ASSERT (m_state == LISTEN);
520 
521  sin_len = sizeof(sin);
522 
523  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len))
524  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
525 
526  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " accepted connection from "
527  << m_remoteAddress << ":" << m_remotePort
528  << " to " << m_localAddress << ":" << m_localPort);
529  //equivalent to FinishBind
532 
534 }
535 
537 { // We would preferred to have scheduled an event directly to
538  // NotifyConnectionSucceeded, but (sigh) these are protected
539  // and we can get the address of it :(
540  struct sockaddr_in sin;
541  size_t sin_len = sizeof(sin);
542  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len)) {
543  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*)&sin.sin_addr);
544  m_localPort = ntohs (sin.sin_port);
545  }
546 
547  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to "
548  << m_remoteAddress << ":" << m_remotePort
549  << " from " << m_localAddress << ":" << m_localPort);
551 }
552 
553 
555 {
556  if (m_state == CLOSED)
557  { // Happens if application closes listening socket after Accept() was scheduled.
558  return false;
559  }
560  NS_ASSERT (m_state == LISTEN);
561 
562  if (!m_nscTcpSocket->is_listening ())
563  {
564  return false;
565  }
566  INetStreamSocket *newsock;
567  int res = m_nscTcpSocket->accept (&newsock);
568  if (res != 0)
569  {
570  return false;
571  }
572 // We could obtain a fromAddress using getpeername, but we've already
573 // finished the tcp handshake here, i.e. this is a new connection
574 // and not a connection request.
575 // if (!NotifyConnectionRequest(fromAddress))
576 // return true;
577 
578  // Clone the socket
579  Ptr<NscTcpSocketImpl> newSock = Copy ();
580  newSock->m_nscTcpSocket = newsock;
581  NS_LOG_LOGIC ("Cloned a NscTcpSocketImpl " << newSock);
582 
584  return true;
585 }
586 
588 {
589  if (m_state != ESTABLISHED)
590  {
591  return false;
592  }
593  int len, err;
594  uint8_t buffer[8192];
595  len = sizeof(buffer);
597  err = m_nscTcpSocket->read_data (buffer, &len);
598  if (err == 0 && len == 0)
599  {
600  NS_LOG_LOGIC ("ReadPendingData got EOF from socket");
602  return false;
603  }
604  m_errno = GetNativeNs3Errno (err);
605  switch (m_errno)
606  {
607  case ERROR_NOTERROR: break; // some data was sent
608  case ERROR_AGAIN: return false;
609  default:
610  NS_LOG_WARN ("Error (" << err << ") " <<
611  "during read_data, ns-3 errno set to" << m_errno);
612  m_state = CLOSED;
613  return false;
614  }
615 
616  Ptr<Packet> p = Create<Packet> (buffer, len);
617 
618  SocketAddressTag tag;
619 
621  p->AddPacketTag (tag);
622  m_deliveryQueue.push (p);
623  m_rxAvailable += p->GetSize ();
624 
625  NotifyDataRecv ();
626  return true;
627 }
628 
630 {
631  NS_LOG_FUNCTION (this);
632  NS_LOG_LOGIC ("ENTERING SendPendingData");
633 
634  if (m_txBuffer.empty ())
635  {
636  return false;
637  }
638 
639  int ret;
640  size_t size, written = 0;
641 
642  do {
643  NS_ASSERT (!m_txBuffer.empty ());
644  Ptr<Packet> &p = m_txBuffer.front ();
645  size = p->GetSize ();
646  NS_ASSERT (size > 0);
647 
649 
650  uint8_t *buf = new uint8_t[size];
651  p->CopyData (buf, size);
652  ret = m_nscTcpSocket->send_data ((const char *)buf, size);
653  delete[] buf;
654 
655  if (ret <= 0)
656  {
657  break;
658  }
659  written += ret;
660 
661  NS_ASSERT (m_txBufferSize >= (size_t)ret);
662  m_txBufferSize -= ret;
663 
664  if ((size_t)ret < size)
665  {
666  p->RemoveAtStart (ret);
667  break;
668  }
669 
670  m_txBuffer.pop ();
671 
672  if (m_txBuffer.empty ())
673  {
674  if (m_closeOnEmpty)
675  {
677  m_state = CLOSED;
678  }
679  break;
680  }
681  } while ((size_t) ret == size);
682 
683  if (written > 0)
684  {
686  return true;
687  }
688  return false;
689 }
690 
692 {
693  return CopyObject<NscTcpSocketImpl> (this);
694 }
695 
696 void
698 {
699  m_sndBufSize = size;
700 }
701 
702 uint32_t
704 {
705  return m_sndBufSize;
706 }
707 
708 void
710 {
711  m_rcvBufSize = size;
712 }
713 
714 uint32_t
716 {
717  return m_rcvBufSize;
718 }
719 
720 void
722 {
723  m_segmentSize = size;
724 }
725 
726 uint32_t
728 {
729  return m_segmentSize;
730 }
731 
732 void
734 {
736 }
737 
738 uint32_t
740 {
741  return m_advertisedWindowSize;
742 }
743 
744 void
746 {
747  m_initialSsThresh = threshold;
748 }
749 
750 uint32_t
752 {
753  return m_initialSsThresh;
754 }
755 
756 void
758 {
759  m_initialCWnd = cwnd;
760 }
761 
762 uint32_t
764 {
765  return m_initialCWnd;
766 }
767 
768 void
770 {
772 }
773 
774 Time
776 {
777  return m_cnTimeout;
778 }
779 
780 void
782 {
783  m_cnCount = count;
784 }
785 
786 uint32_t
788 {
789  return m_cnCount;
790 }
791 
792 void
794 {
796 }
797 
798 Time
800 {
801  return m_delAckTimeout;
802 }
803 
804 void
806 {
807  m_delAckMaxCount = count;
808 }
809 
810 uint32_t
812 {
813  return m_delAckMaxCount;
814 }
815 
816 void
818 {
819  m_noDelay = noDelay;
820 }
821 
822 bool
824 {
825  return m_noDelay;
826 }
827 
828 void
830 {
832 }
833 
834 Time
836 {
837  return m_persistTimeout;
838 }
839 
842 {
843  enum nsc_errno err;
844 
845  if (error >= 0)
846  {
847  return ERROR_NOTERROR;
848  }
849  err = (enum nsc_errno) error;
850  switch (err)
851  {
852  case NSC_EADDRINUSE: // fallthrough
854  case NSC_EINPROGRESS: // Altough nsc sockets are nonblocking, we pretend they're not.
855  case NSC_EAGAIN: return ERROR_AGAIN;
856  case NSC_EISCONN: // fallthrough
857  case NSC_EALREADY: return ERROR_ISCONN;
859  case NSC_ECONNRESET: // for no, all of these fall through
860  case NSC_EHOSTDOWN:
861  case NSC_ENETUNREACH:
863  case NSC_EMSGSIZE: return ERROR_MSGSIZE;
864  case NSC_ENOTCONN: return ERROR_NOTCONN;
865  case NSC_ESHUTDOWN: return ERROR_SHUTDOWN;
866  case NSC_ETIMEDOUT: return ERROR_NOTCONN;
867  case NSC_ENOTDIR: // used by eg. sysctl(2). Shouldn't happen normally,
868  // but is triggered by e.g. show_config().
869  case NSC_EUNKNOWN: return ERROR_INVAL; // Catches stacks that 'return -1' without real mapping
870  }
871  NS_ASSERT_MSG (0, "Unknown NSC error");
872  return ERROR_INVAL;
873 }
874 
875 bool
877 {
878  if (allowBroadcast)
879  {
880  return false;
881  }
882  return true;
883 }
884 
885 bool
887 {
888  return false;
889 }
890 
891 } // namespace ns3
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
static Ipv4Address Deserialize(const uint8_t buf[4])
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
an Inet address class
Ipv4Address GetIpv4(void) const
static Ipv4Address GetAny(void)
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
virtual int ShutdownSend(void)
std::queue< Ptr< Packet > > m_deliveryQueue
receive buffer
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
virtual bool is_listening()=0
Check the listening state.
(abstract) base class of all TcpSockets
Definition: tcp-socket.h:46
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Connection established.
Definition: tcp-socket.h:70
virtual int GetSockName(Address &address) const
Get socket address.
virtual void SetSndBufSize(uint32_t size)
Set the send buffer size.
uint32_t m_txBufferSize
transmission buffer size
virtual enum SocketType GetSocketType(void) const
Ipv4Address m_localAddress
local address
Sent a connection request, waiting for ack.
Definition: tcp-socket.h:67
void NotifyDataRecv(void)
Notify through the callback (if set) that some data have been received.
Definition: socket.cc:305
NscTcpSocketImpl()
Create an unbound tcp socket.
Ptr< Node > m_node
the associated node
virtual uint32_t GetAdvWin(void) const
Get the Advertised Window size.
void SetRxCallback(Callback< void, Ptr< Packet >, Ipv4Header, uint16_t, Ptr< Ipv4Interface > > callback)
Set the reception callback.
virtual void SetAdvWin(uint32_t window)
Set the Advertised Window size.
Ptr< Packet > Recv(void)
Read a single packet from the socket.
Definition: socket.cc:175
uint32_t m_rxAvailable
receive buffer available size
void SetDestroyCallback(Callback< void > callback)
Set the default destroy callback.
Socket is finished.
Definition: tcp-socket.h:65
enum Socket::SocketErrno GetNativeNs3Errno(int err) const
Translate between a NSC error and a ns-3 error code.
virtual Time GetConnTimeout(void) const
Get the connection timeout.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:822
void SetAddress(Address addr)
Set the tag's address.
Definition: socket.cc:523
bool SendPendingData(void)
Send all the pending data.
uint32_t m_rcvBufSize
maximum receive socket buffer size
Ipv4Address m_remoteAddress
peer IP address
virtual uint32_t GetConnCount(void) const
Get the number of connection retries before giving up.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
INetStreamSocket * m_nscTcpSocket
the real NSC TCP socket
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
TracedValue< TcpStates_t > m_state
state information
virtual int Bind6(void)
Allocate a local IPv6 endpoint for this socket.
uint32_t m_sndBufSize
buffer limit for the outgoing queue
virtual int accept(INetStreamSocket **)=0
Accept an incoming connection.
static TypeId GetTypeId(void)
Get the type ID.
virtual void SetConnTimeout(Time timeout)
Set the connection timeout.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
SocketType
Enumeration of the possible socket types.
Definition: socket.h:104
virtual uint32_t GetRcvBufSize(void) const
Get the receive buffer size.
bool m_shutdownSend
Send no longer allowed.
virtual void SetInitialCwnd(uint32_t cwnd)
Set the initial Congestion Window.
virtual void SetPersistTimeout(Time timeout)
Set the timout for persistent connection.
ns3::Time timeout
InetSocketAddress m_peerAddress
peer IP and port
bool m_closeOnEmpty
true if socket will close when buffer is empty
virtual void connect(const char *, int)=0
Connect to a remote peer.
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:90
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
bool ReadPendingData(void)
Read all the pending data.
virtual uint32_t GetSegSize(void) const
Get the segment size.
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
Packet header for IPv4.
Definition: ipv4-header.h:31
Time m_cnTimeout
Timeout for connection retry.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:844
virtual Time GetDelAckTimeout(void) const
Get the time to delay an ACK.
uint32_t m_initialCWnd
Initial cWnd value.
void SetNode(Ptr< Node > node)
Set the associated node.
enum SocketErrno m_errno
last error number
uint32_t m_initialSsThresh
Initial Slow Start Threshold.
virtual void SetTcpNoDelay(bool noDelay)
Enable/Disable Nagle's algorithm.
bool m_connected
Connection established.
virtual uint32_t GetDelAckMaxCount(void) const
Get the number of packet to fire an ACK before delay timeout.
Socket logic for the NSC TCP sockets.
Ipv4Address GetLocalAddress(void)
Get the local address.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
Time m_persistTimeout
Time between sending 1-byte probes.
virtual int send_data(const void *data, int datalen)=0
Send some data.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
This class implements a tag that carries an address of a packet across the socket interface...
Definition: socket.h:951
virtual bool GetTcpNoDelay(void) const
Check if Nagle's algorithm is enabled or not.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1480
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:285
virtual int ShutdownRecv(void)
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
void Print(std::ostream &os) const
Print this address to the given output stream.
void ForwardUp(Ptr< Packet > p, Ipv4Header header, uint16_t port, Ptr< Ipv4Interface > incomingInterface)
Called by the L3 protocol when it received a packet to pass on to TCP.
virtual bool is_connected()=0
Check the connection state.
virtual Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
virtual void SetRcvBufSize(uint32_t size)
Set the receive buffer size.
uint32_t m_cnCount
Count of remaining connection retries.
virtual Time GetPersistTimeout(void) const
Get the timout for persistent connection.
virtual int Listen(void)
Listen for incoming connections.
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
void NotifyConnectionSucceeded(void)
Notify through the callback (if set) that the connection has been established.
Definition: socket.cc:217
void CompleteFork(void)
Complete the Fork operations (after a connection has been accepted)
uint16_t m_remotePort
peer port
Ptr< NscTcpL4Protocol > m_tcp
the associated TCP L4 protocol
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static InetSocketAddress ConvertFrom(const Address &address)
Returns an InetSocketAddress which corresponds to the input Address.
void NotifyNewConnectionCreated(Ptr< Socket > socket, const Address &from)
Notify through the callback (if set) that a new connection has been created.
Definition: socket.cc:275
virtual void SetSegSize(uint32_t size)
Set the segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
bool m_noDelay
Disable ACk delay.
virtual uint32_t GetInitialSSThresh(void) const
Get the initial Slow Start Threshold.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:1379
virtual void SetConnCount(uint32_t count)
Set the number of connection retries before giving up.
bool m_shutdownRecv
Receive no longer allowed.
Time m_delAckTimeout
Time to delay an ACK.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
uint32_t m_rxWindowSize
Receive window size.
void SetTcp(Ptr< NscTcpL4Protocol > tcp)
Set the associated TCP L4 protocol.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
int FinishBind(void)
Finish the binding process.
uint32_t m_delAckMaxCount
Number of packet to fire an ACK before delay timeout.
nsc_errno
Definition: sim_errno.h:35
virtual int getpeername(struct sockaddr *sa, size_t *salen)
Get the peer name.
virtual int getsockname(struct sockaddr *sa, size_t *salen)
Get the socket local name.
uint16_t GetLocalPort(void)
Get the local port.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
Address GetAddress(void) const
Get the tag's address.
Definition: socket.cc:530
virtual uint32_t GetSndBufSize(void) const
Get the send buffer size.
bool Accept(void)
Accept an incoming connection.
virtual int Close(void)
Close a socket.
virtual void listen(int)=0
Put the socket in Listening state on a port.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void ConnectionSucceeded()
Called when a connection is in Established state.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
Struct interface to NSC Stream (i.e., TCP) Sockets.
Remote side has shutdown and is waiting for us to finish writing our data and to shutdown (we have to...
Definition: tcp-socket.h:71
virtual void disconnect()=0
Disconnect from a remote peer.
Listening for a connection.
Definition: tcp-socket.h:66
uint16_t GetPort(void) const
virtual int read_data(void *buf, int *buflen)=0
Read some data.
uint16_t m_localPort
local port
tuple address
Definition: first.py:37
Ptr< NscTcpSocketImpl > Copy()
Copy self.
std::queue< Ptr< Packet > > m_txBuffer
transmission buffer
virtual void SetDelAckMaxCount(uint32_t count)
Set the number of packet to fire an ACK before delay timeout.
virtual int SendTo(Ptr< Packet > p, uint32_t flags, const Address &toAddress)
Send data to a specified peer.
virtual void SetInitialSSThresh(uint32_t threshold)
Set the initial Slow Start Threshold.
uint32_t m_advertisedWindowSize
Window to advertise.
TracedValue< uint32_t > m_ssThresh
Slow Start Threshold.
a unique identifier for an interface.
Definition: type-id.h:58
virtual void SetDelAckTimeout(Time timeout)
Set the time to delay an ACK.
uint32_t m_segmentSize
SegmentSize.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:826
static bool IsMatchingType(const Address &address)
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
virtual uint32_t GetInitialCwnd(void) const
Get the initial Congestion Window.
void NSCWakeup(void)
Called by NscTcpSocketImpl::ForwardUp()