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_synRetries (sock.m_synRetries),
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  GetPeerName (fromAddress);
465  return packet;
466 }
467 
468 int
470 {
473  return 0;
474 }
475 
476 int
478 {
479  NS_LOG_FUNCTION (this << address);
480 
481  if (!m_endPoint)
482  {
484  return -1;
485  }
487  m_endPoint->GetPeerPort ());
488  return 0;
489 }
490 
491 uint32_t
493 {
495  // We separately maintain this state to avoid walking the queue
496  // every time this might be called
497  return m_rxAvailable;
498 }
499 
500 void
502  Ptr<Ipv4Interface> incomingInterface)
503 {
504  NSCWakeup ();
505 }
506 
508 {
509  // The address pairs (m_localAddress, m_localPort, m_remoteAddress, m_remotePort)
510  // are bogus, but this isn't important at the moment, because
511  // address <-> Socket handling is done by NSC internally.
512  // We only need to add the new ns-3 socket to the list of sockets, so
513  // we use plain Allocate() instead of Allocate(m_localAddress, ... )
514  struct sockaddr_in sin;
515  size_t sin_len = sizeof(sin);
516 
517  if (0 == m_nscTcpSocket->getpeername ((struct sockaddr*) &sin, &sin_len)) {
518  m_remotePort = ntohs (sin.sin_port);
519  m_remoteAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
521  }
522 
523  m_endPoint = m_tcp->Allocate ();
524 
525  //the cloned socket with be in listen state, so manually change state
526  NS_ASSERT (m_state == LISTEN);
528 
529  sin_len = sizeof(sin);
530 
531  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len))
532  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
533 
534  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " accepted connection from "
535  << m_remoteAddress << ":" << m_remotePort
536  << " to " << m_localAddress << ":" << m_localPort);
537  //equivalent to FinishBind
540 
542 }
543 
545 { // We would preferred to have scheduled an event directly to
546  // NotifyConnectionSucceeded, but (sigh) these are protected
547  // and we can get the address of it :(
548  struct sockaddr_in sin;
549  size_t sin_len = sizeof(sin);
550  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len)) {
551  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*)&sin.sin_addr);
552  m_localPort = ntohs (sin.sin_port);
553  }
554 
555  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to "
556  << m_remoteAddress << ":" << m_remotePort
557  << " from " << m_localAddress << ":" << m_localPort);
559 }
560 
561 
563 {
564  if (m_state == CLOSED)
565  { // Happens if application closes listening socket after Accept() was scheduled.
566  return false;
567  }
568  NS_ASSERT (m_state == LISTEN);
569 
570  if (!m_nscTcpSocket->is_listening ())
571  {
572  return false;
573  }
574  INetStreamSocket *newsock;
575  int res = m_nscTcpSocket->accept (&newsock);
576  if (res != 0)
577  {
578  return false;
579  }
580 // We could obtain a fromAddress using getpeername, but we've already
581 // finished the tcp handshake here, i.e. this is a new connection
582 // and not a connection request.
583 // if (!NotifyConnectionRequest(fromAddress))
584 // return true;
585 
586  // Clone the socket
587  Ptr<NscTcpSocketImpl> newSock = Copy ();
588  newSock->m_nscTcpSocket = newsock;
589  NS_LOG_LOGIC ("Cloned a NscTcpSocketImpl " << newSock);
590 
592  return true;
593 }
594 
596 {
597  if (m_state != ESTABLISHED)
598  {
599  return false;
600  }
601  int len, err;
602  uint8_t buffer[8192];
603  len = sizeof(buffer);
605  err = m_nscTcpSocket->read_data (buffer, &len);
606  if (err == 0 && len == 0)
607  {
608  NS_LOG_LOGIC ("ReadPendingData got EOF from socket");
610  return false;
611  }
612  m_errno = GetNativeNs3Errno (err);
613  switch (m_errno)
614  {
615  case ERROR_NOTERROR: break; // some data was sent
616  case ERROR_AGAIN: return false;
617  default:
618  NS_LOG_WARN ("Error (" << err << ") " <<
619  "during read_data, ns-3 errno set to" << m_errno);
620  m_state = CLOSED;
621  return false;
622  }
623 
624  Ptr<Packet> p = Create<Packet> (buffer, len);
625 
626  m_deliveryQueue.push (p);
627  m_rxAvailable += p->GetSize ();
628 
629  NotifyDataRecv ();
630  return true;
631 }
632 
634 {
635  NS_LOG_FUNCTION (this);
636  NS_LOG_LOGIC ("ENTERING SendPendingData");
637 
638  if (m_txBuffer.empty ())
639  {
640  return false;
641  }
642 
643  int ret;
644  size_t size, written = 0;
645 
646  do {
647  NS_ASSERT (!m_txBuffer.empty ());
648  Ptr<Packet> &p = m_txBuffer.front ();
649  size = p->GetSize ();
650  NS_ASSERT (size > 0);
651 
653 
654  uint8_t *buf = new uint8_t[size];
655  p->CopyData (buf, size);
656  ret = m_nscTcpSocket->send_data ((const char *)buf, size);
657  delete[] buf;
658 
659  if (ret <= 0)
660  {
661  break;
662  }
663  written += ret;
664 
665  NS_ASSERT (m_txBufferSize >= (size_t)ret);
666  m_txBufferSize -= ret;
667 
668  if ((size_t)ret < size)
669  {
670  p->RemoveAtStart (ret);
671  break;
672  }
673 
674  m_txBuffer.pop ();
675 
676  if (m_txBuffer.empty ())
677  {
678  if (m_closeOnEmpty)
679  {
681  m_state = CLOSED;
682  }
683  break;
684  }
685  } while ((size_t) ret == size);
686 
687  if (written > 0)
688  {
690  return true;
691  }
692  return false;
693 }
694 
696 {
697  return CopyObject<NscTcpSocketImpl> (this);
698 }
699 
700 void
702 {
703  m_sndBufSize = size;
704 }
705 
706 uint32_t
708 {
709  return m_sndBufSize;
710 }
711 
712 void
714 {
715  m_rcvBufSize = size;
716 }
717 
718 uint32_t
720 {
721  return m_rcvBufSize;
722 }
723 
724 void
726 {
727  m_segmentSize = size;
728 }
729 
730 uint32_t
732 {
733  return m_segmentSize;
734 }
735 
736 void
738 {
740 }
741 
742 uint32_t
744 {
745  return m_advertisedWindowSize;
746 }
747 
748 void
750 {
751  m_initialSsThresh = threshold;
752 }
753 
754 uint32_t
756 {
757  return m_initialSsThresh;
758 }
759 
760 void
762 {
763  m_initialCWnd = cwnd;
764 }
765 
766 uint32_t
768 {
769  return m_initialCWnd;
770 }
771 
772 void
774 {
776 }
777 
778 Time
780 {
781  return m_cnTimeout;
782 }
783 
784 void
786 {
787  m_synRetries = count;
788 }
789 
790 uint32_t
792 {
793  return m_synRetries;
794 }
795 
796 void
798 {
800 }
801 
802 void
804 {
805  NS_LOG_FUNCTION (this << retries);
806  m_dataRetries = retries;
807 }
808 
809 uint32_t
811 {
812  NS_LOG_FUNCTION (this);
813  return m_dataRetries;
814 }
815 
816 Time
818 {
819  return m_delAckTimeout;
820 }
821 
822 void
824 {
825  m_delAckMaxCount = count;
826 }
827 
828 uint32_t
830 {
831  return m_delAckMaxCount;
832 }
833 
834 void
836 {
837  m_noDelay = noDelay;
838 }
839 
840 bool
842 {
843  return m_noDelay;
844 }
845 
846 void
848 {
850 }
851 
852 Time
854 {
855  return m_persistTimeout;
856 }
857 
860 {
861  enum nsc_errno err;
862 
863  if (error >= 0)
864  {
865  return ERROR_NOTERROR;
866  }
867  err = (enum nsc_errno) error;
868  switch (err)
869  {
870  case NSC_EADDRINUSE: // fallthrough
872  case NSC_EINPROGRESS: // Altough nsc sockets are nonblocking, we pretend they're not.
873  case NSC_EAGAIN: return ERROR_AGAIN;
874  case NSC_EISCONN: // fallthrough
875  case NSC_EALREADY: return ERROR_ISCONN;
877  case NSC_ECONNRESET: // for no, all of these fall through
878  case NSC_EHOSTDOWN:
879  case NSC_ENETUNREACH:
881  case NSC_EMSGSIZE: return ERROR_MSGSIZE;
882  case NSC_ENOTCONN: return ERROR_NOTCONN;
883  case NSC_ESHUTDOWN: return ERROR_SHUTDOWN;
884  case NSC_ETIMEDOUT: return ERROR_NOTCONN;
885  case NSC_ENOTDIR: // used by eg. sysctl(2). Shouldn't happen normally,
886  // but is triggered by e.g. show_config().
887  case NSC_EUNKNOWN: return ERROR_INVAL; // Catches stacks that 'return -1' without real mapping
888  }
889  NS_ASSERT_MSG (0, "Unknown NSC error");
890  return ERROR_INVAL;
891 }
892 
893 bool
895 {
896  if (allowBroadcast)
897  {
898  return false;
899  }
900  return true;
901 }
902 
903 bool
905 {
906  return false;
907 }
908 
909 } // 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
Connection established.
Definition: tcp-socket.h:71
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:47
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
virtual int GetSockName(Address &address) const
Get socket address.
virtual uint32_t GetSynRetries(void) const
Get the number of connection retries before giving up.
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
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.
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.
bool SendPendingData(void)
Send all the pending data.
uint32_t m_rcvBufSize
maximum receive socket buffer size
Ipv4Address m_remoteAddress
peer IP address
virtual void SetDataRetries(uint32_t retries)
Set the number of data transmission 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:792
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.
nsc_errno
List of network stack errors that may happen in a simulation, and can be handled by the simulator in ...
Definition: sim_errno.h:41
#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:33
Time m_cnTimeout
Timeout for connection retry.
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.
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:1489
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.
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:1401
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
Remote side has shutdown and is waiting for us to finish writing our data and to shutdown (we have to...
Definition: tcp-socket.h:72
Sent a connection request, waiting for ack.
Definition: tcp-socket.h:68
virtual void SetSynRetries(uint32_t count)
Set the number of connection retries before giving up.
uint32_t m_synRetries
Count of remaining connection retries.
Socket is finished.
Definition: tcp-socket.h:66
Listening for a connection.
Definition: tcp-socket.h:67
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.
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
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
Ipv4Address GetPeerAddress(void)
Get the peer address.
uint16_t GetPeerPort(void)
Get the peer port.
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.
virtual void disconnect()=0
Disconnect from a remote peer.
uint16_t GetPort(void) const
virtual uint32_t GetDataRetries(void) const
Get the number of data transmission retries before giving up.
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:904
static bool IsMatchingType(const Address &address)
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
uint32_t m_dataRetries
Count of remaining data retransmission attempts.
virtual uint32_t GetInitialCwnd(void) const
Get the initial Congestion Window.
void NSCWakeup(void)
Called by NscTcpSocketImpl::ForwardUp()