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  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 int
485 {
486  NS_LOG_FUNCTION (this << address);
487 
488  if (!m_endPoint)
489  {
491  return -1;
492  }
494  m_endPoint->GetPeerPort ());
495  return 0;
496 }
497 
498 uint32_t
500 {
502  // We separately maintain this state to avoid walking the queue
503  // every time this might be called
504  return m_rxAvailable;
505 }
506 
507 void
509  Ptr<Ipv4Interface> incomingInterface)
510 {
511  NSCWakeup ();
512 }
513 
515 {
516  // The address pairs (m_localAddress, m_localPort, m_remoteAddress, m_remotePort)
517  // are bogus, but this isn't important at the moment, because
518  // address <-> Socket handling is done by NSC internally.
519  // We only need to add the new ns-3 socket to the list of sockets, so
520  // we use plain Allocate() instead of Allocate(m_localAddress, ... )
521  struct sockaddr_in sin;
522  size_t sin_len = sizeof(sin);
523 
524  if (0 == m_nscTcpSocket->getpeername ((struct sockaddr*) &sin, &sin_len)) {
525  m_remotePort = ntohs (sin.sin_port);
526  m_remoteAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
528  }
529 
530  m_endPoint = m_tcp->Allocate ();
531 
532  //the cloned socket with be in listen state, so manually change state
533  NS_ASSERT (m_state == LISTEN);
535 
536  sin_len = sizeof(sin);
537 
538  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len))
539  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
540 
541  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " accepted connection from "
542  << m_remoteAddress << ":" << m_remotePort
543  << " to " << m_localAddress << ":" << m_localPort);
544  //equivalent to FinishBind
547 
549 }
550 
552 { // We would preferred to have scheduled an event directly to
553  // NotifyConnectionSucceeded, but (sigh) these are protected
554  // and we can get the address of it :(
555  struct sockaddr_in sin;
556  size_t sin_len = sizeof(sin);
557  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len)) {
558  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*)&sin.sin_addr);
559  m_localPort = ntohs (sin.sin_port);
560  }
561 
562  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to "
563  << m_remoteAddress << ":" << m_remotePort
564  << " from " << m_localAddress << ":" << m_localPort);
566 }
567 
568 
570 {
571  if (m_state == CLOSED)
572  { // Happens if application closes listening socket after Accept() was scheduled.
573  return false;
574  }
575  NS_ASSERT (m_state == LISTEN);
576 
577  if (!m_nscTcpSocket->is_listening ())
578  {
579  return false;
580  }
581  INetStreamSocket *newsock;
582  int res = m_nscTcpSocket->accept (&newsock);
583  if (res != 0)
584  {
585  return false;
586  }
587 // We could obtain a fromAddress using getpeername, but we've already
588 // finished the tcp handshake here, i.e. this is a new connection
589 // and not a connection request.
590 // if (!NotifyConnectionRequest(fromAddress))
591 // return true;
592 
593  // Clone the socket
594  Ptr<NscTcpSocketImpl> newSock = Copy ();
595  newSock->m_nscTcpSocket = newsock;
596  NS_LOG_LOGIC ("Cloned a NscTcpSocketImpl " << newSock);
597 
599  return true;
600 }
601 
603 {
604  if (m_state != ESTABLISHED)
605  {
606  return false;
607  }
608  int len, err;
609  uint8_t buffer[8192];
610  len = sizeof(buffer);
612  err = m_nscTcpSocket->read_data (buffer, &len);
613  if (err == 0 && len == 0)
614  {
615  NS_LOG_LOGIC ("ReadPendingData got EOF from socket");
617  return false;
618  }
619  m_errno = GetNativeNs3Errno (err);
620  switch (m_errno)
621  {
622  case ERROR_NOTERROR: break; // some data was sent
623  case ERROR_AGAIN: return false;
624  default:
625  NS_LOG_WARN ("Error (" << err << ") " <<
626  "during read_data, ns-3 errno set to" << m_errno);
627  m_state = CLOSED;
628  return false;
629  }
630 
631  Ptr<Packet> p = Create<Packet> (buffer, len);
632 
633  SocketAddressTag tag;
634 
636  p->AddPacketTag (tag);
637  m_deliveryQueue.push (p);
638  m_rxAvailable += p->GetSize ();
639 
640  NotifyDataRecv ();
641  return true;
642 }
643 
645 {
646  NS_LOG_FUNCTION (this);
647  NS_LOG_LOGIC ("ENTERING SendPendingData");
648 
649  if (m_txBuffer.empty ())
650  {
651  return false;
652  }
653 
654  int ret;
655  size_t size, written = 0;
656 
657  do {
658  NS_ASSERT (!m_txBuffer.empty ());
659  Ptr<Packet> &p = m_txBuffer.front ();
660  size = p->GetSize ();
661  NS_ASSERT (size > 0);
662 
664 
665  uint8_t *buf = new uint8_t[size];
666  p->CopyData (buf, size);
667  ret = m_nscTcpSocket->send_data ((const char *)buf, size);
668  delete[] buf;
669 
670  if (ret <= 0)
671  {
672  break;
673  }
674  written += ret;
675 
676  NS_ASSERT (m_txBufferSize >= (size_t)ret);
677  m_txBufferSize -= ret;
678 
679  if ((size_t)ret < size)
680  {
681  p->RemoveAtStart (ret);
682  break;
683  }
684 
685  m_txBuffer.pop ();
686 
687  if (m_txBuffer.empty ())
688  {
689  if (m_closeOnEmpty)
690  {
692  m_state = CLOSED;
693  }
694  break;
695  }
696  } while ((size_t) ret == size);
697 
698  if (written > 0)
699  {
701  return true;
702  }
703  return false;
704 }
705 
707 {
708  return CopyObject<NscTcpSocketImpl> (this);
709 }
710 
711 void
713 {
714  m_sndBufSize = size;
715 }
716 
717 uint32_t
719 {
720  return m_sndBufSize;
721 }
722 
723 void
725 {
726  m_rcvBufSize = size;
727 }
728 
729 uint32_t
731 {
732  return m_rcvBufSize;
733 }
734 
735 void
737 {
738  m_segmentSize = size;
739 }
740 
741 uint32_t
743 {
744  return m_segmentSize;
745 }
746 
747 void
749 {
751 }
752 
753 uint32_t
755 {
756  return m_advertisedWindowSize;
757 }
758 
759 void
761 {
762  m_initialSsThresh = threshold;
763 }
764 
765 uint32_t
767 {
768  return m_initialSsThresh;
769 }
770 
771 void
773 {
774  m_initialCWnd = cwnd;
775 }
776 
777 uint32_t
779 {
780  return m_initialCWnd;
781 }
782 
783 void
785 {
787 }
788 
789 Time
791 {
792  return m_cnTimeout;
793 }
794 
795 void
797 {
798  m_synRetries = count;
799 }
800 
801 uint32_t
803 {
804  return m_synRetries;
805 }
806 
807 void
809 {
811 }
812 
813 void
815 {
816  NS_LOG_FUNCTION (this << retries);
817  m_dataRetries = retries;
818 }
819 
820 uint32_t
822 {
823  NS_LOG_FUNCTION (this);
824  return m_dataRetries;
825 }
826 
827 Time
829 {
830  return m_delAckTimeout;
831 }
832 
833 void
835 {
836  m_delAckMaxCount = count;
837 }
838 
839 uint32_t
841 {
842  return m_delAckMaxCount;
843 }
844 
845 void
847 {
848  m_noDelay = noDelay;
849 }
850 
851 bool
853 {
854  return m_noDelay;
855 }
856 
857 void
859 {
861 }
862 
863 Time
865 {
866  return m_persistTimeout;
867 }
868 
871 {
872  enum nsc_errno err;
873 
874  if (error >= 0)
875  {
876  return ERROR_NOTERROR;
877  }
878  err = (enum nsc_errno) error;
879  switch (err)
880  {
881  case NSC_EADDRINUSE: // fallthrough
883  case NSC_EINPROGRESS: // Altough nsc sockets are nonblocking, we pretend they're not.
884  case NSC_EAGAIN: return ERROR_AGAIN;
885  case NSC_EISCONN: // fallthrough
886  case NSC_EALREADY: return ERROR_ISCONN;
888  case NSC_ECONNRESET: // for no, all of these fall through
889  case NSC_EHOSTDOWN:
890  case NSC_ENETUNREACH:
892  case NSC_EMSGSIZE: return ERROR_MSGSIZE;
893  case NSC_ENOTCONN: return ERROR_NOTCONN;
894  case NSC_ESHUTDOWN: return ERROR_SHUTDOWN;
895  case NSC_ETIMEDOUT: return ERROR_NOTCONN;
896  case NSC_ENOTDIR: // used by eg. sysctl(2). Shouldn't happen normally,
897  // but is triggered by e.g. show_config().
898  case NSC_EUNKNOWN: return ERROR_INVAL; // Catches stacks that 'return -1' without real mapping
899  }
900  NS_ASSERT_MSG (0, "Unknown NSC error");
901  return ERROR_INVAL;
902 }
903 
904 bool
906 {
907  if (allowBroadcast)
908  {
909  return false;
910  }
911  return true;
912 }
913 
914 bool
916 {
917  return false;
918 }
919 
920 } // 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 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
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:824
void SetAddress(Address addr)
Set the tag's address.
Definition: socket.cc:555
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: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:846
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:1005
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.
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 int GetPeerName(Address &address) const
Get the peer address of a connected socket.
virtual void SetSynRetries(uint32_t count)
Set the number of connection retries before giving up.
uint32_t m_synRetries
Count of remaining connection retries.
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:562
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.
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 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:826
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()