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  .AddTraceSource ("CongestionWindow",
58  "The TCP connection's congestion window",
60  "ns3::TracedValue::Uint32Callback")
61  .AddTraceSource ("SlowStartThreshold",
62  "TCP slow start threshold (bytes)",
64  "ns3::TracedValue::Uint32Callback")
65  .AddTraceSource ("State",
66  "TCP state",
68  "ns3::TcpStatesTracedValueCallback")
69  ;
70  return tid;
71 }
72 
74  : m_endPoint (0),
75  m_node (0),
76  m_tcp (0),
77  m_localAddress (Ipv4Address::GetZero ()),
78  m_localPort (0),
79  m_peerAddress ("0.0.0.0", 0),
80  m_errno (ERROR_NOTERROR),
81  m_shutdownSend (false),
82  m_shutdownRecv (false),
83  m_connected (false),
84  m_state (CLOSED),
85  m_closeOnEmpty (false),
86  m_txBufferSize (0),
87  m_lastMeasuredRtt (Seconds (0.0))
88 {
89  NS_LOG_FUNCTION (this);
90 }
91 
93  : TcpSocket (sock), //copy the base class callbacks
94  m_delAckMaxCount (sock.m_delAckMaxCount),
95  m_delAckTimeout (sock.m_delAckTimeout),
96  m_noDelay (sock.m_noDelay),
97  m_endPoint (0),
98  m_node (sock.m_node),
99  m_tcp (sock.m_tcp),
100  m_remoteAddress (sock.m_remoteAddress),
101  m_remotePort (sock.m_remotePort),
102  m_localAddress (sock.m_localAddress),
103  m_localPort (sock.m_localPort),
104  m_peerAddress (sock.m_peerAddress),
105  m_errno (sock.m_errno),
106  m_shutdownSend (sock.m_shutdownSend),
107  m_shutdownRecv (sock.m_shutdownRecv),
108  m_connected (sock.m_connected),
109  m_state (sock.m_state),
110  m_closeOnEmpty (sock.m_closeOnEmpty),
111  m_txBufferSize (sock.m_txBufferSize),
112  m_segmentSize (sock.m_segmentSize),
113  m_rxWindowSize (sock.m_rxWindowSize),
114  m_advertisedWindowSize (sock.m_advertisedWindowSize),
115  m_cWnd (sock.m_cWnd),
116  m_ssThresh (sock.m_ssThresh),
117  m_initialCWnd (sock.m_initialCWnd),
118  m_initialSsThresh (sock.m_initialSsThresh),
119  m_lastMeasuredRtt (Seconds (0.0)),
120  m_cnTimeout (sock.m_cnTimeout),
121  m_cnCount (sock.m_cnCount),
122  m_rxAvailable (0),
123  m_nscTcpSocket (0),
124  m_sndBufSize (sock.m_sndBufSize)
125 {
127  NS_LOG_LOGIC ("Invoked the copy constructor");
128  //copy the pending data if necessary
129  if(!sock.m_txBuffer.empty () )
130  {
131  m_txBuffer = sock.m_txBuffer;
132  }
133  //can't "copy" the endpoint just yes, must do this when we know the peer info
134  //too; this is in SYN_ACK_TX
135 }
136 
138 {
139  NS_LOG_FUNCTION (this);
140  m_node = 0;
141  if (m_endPoint != 0)
142  {
143  NS_ASSERT (m_tcp != 0);
152  NS_ASSERT (m_endPoint != 0);
153  m_tcp->DeAllocate (m_endPoint);
154  NS_ASSERT (m_endPoint == 0);
155  }
156  m_tcp = 0;
157 }
158 
159 void
161 {
162  m_node = node;
163  // Initialize some variables
167 }
168 
169 void
171 {
172  m_nscTcpSocket = tcp->m_nscStack->new_tcp_socket ();
173  m_tcp = tcp;
174 }
175 
176 
179 {
181  return m_errno;
182 }
183 
186 {
187  return NS3_SOCK_STREAM;
188 }
189 
190 Ptr<Node>
192 {
194  return m_node;
195 }
196 
197 void
199 {
201  m_node = 0;
202  m_endPoint = 0;
203  m_tcp = 0;
204 }
205 int
207 {
209  if (m_endPoint == 0)
210  {
211  return -1;
212  }
217  return 0;
218 }
219 
220 int
222 {
224  m_endPoint = m_tcp->Allocate ();
225  return FinishBind ();
226 }
227 int
229 {
230  NS_LOG_LOGIC ("NscTcpSocketImpl: ERROR_AFNOSUPPORT - Bind6 not supported");
232  return (-1);
233 }
234 int
236 {
237  NS_LOG_FUNCTION (this<<address);
238  if (!InetSocketAddress::IsMatchingType (address))
239  {
240  return ERROR_INVAL;
241  }
243  Ipv4Address ipv4 = transport.GetIpv4 ();
244  uint16_t port = transport.GetPort ();
245  if (ipv4 == Ipv4Address::GetAny () && port == 0)
246  {
247  m_endPoint = m_tcp->Allocate ();
248  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
249  }
250  else if (ipv4 == Ipv4Address::GetAny () && port != 0)
251  {
252  m_endPoint = m_tcp->Allocate (port);
253  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
254  }
255  else if (ipv4 != Ipv4Address::GetAny () && port == 0)
256  {
257  m_endPoint = m_tcp->Allocate (ipv4);
258  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
259  }
260  else if (ipv4 != Ipv4Address::GetAny () && port != 0)
261  {
262  m_endPoint = m_tcp->Allocate (ipv4, port);
263  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
264  }
265 
266  m_localPort = port;
267  return FinishBind ();
268 }
269 
270 int
272 {
274  m_shutdownSend = true;
275  return 0;
276 }
277 int
279 {
281  m_shutdownRecv = true;
282  return 0;
283 }
284 
285 int
287 {
288  NS_LOG_FUNCTION (this << m_state);
289 
290  if (m_state == CLOSED)
291  {
292  return -1;
293  }
294  if (!m_txBuffer.empty ())
295  { // App close with pending data must wait until all data transmitted
296  m_closeOnEmpty = true;
297  NS_LOG_LOGIC ("Socket " << this <<
298  " deferring close, state " << m_state);
299  return 0;
300  }
301 
302  NS_LOG_LOGIC ("NscTcp socket " << this << " calling disconnect(); moving to CLOSED");
304  m_state = CLOSED;
305  ShutdownSend ();
306  return 0;
307 }
308 
309 int
311 {
312  NS_LOG_FUNCTION (this << address);
313  if (m_endPoint == 0)
314  {
315  if (Bind () == -1)
316  {
317  NS_ASSERT (m_endPoint == 0);
318  return -1;
319  }
320  NS_ASSERT (m_endPoint != 0);
321  }
323  m_remoteAddress = transport.GetIpv4 ();
324  m_remotePort = transport.GetPort ();
325 
326  std::ostringstream ss;
327  m_remoteAddress.Print (ss);
328  std::string ipstring = ss.str ();
329 
330  m_nscTcpSocket->connect (ipstring.c_str (), m_remotePort);
331  m_state = SYN_SENT;
332  return 0;
333 }
334 
335 int
336 NscTcpSocketImpl::Send (const Ptr<Packet> p, uint32_t flags)
337 {
338  NS_LOG_FUNCTION (this << p);
339 
340  NS_ASSERT (p->GetSize () > 0);
342  {
343  if (p->GetSize () > GetTxAvailable ())
344  {
346  return -1;
347  }
348 
349  uint32_t sent = p->GetSize ();
350  if (m_state == ESTABLISHED)
351  {
352  m_txBuffer.push (p);
353  m_txBufferSize += sent;
354  SendPendingData ();
355  }
356  else
357  { // SYN_SET -- Queue Data
358  m_txBuffer.push (p);
359  m_txBufferSize += sent;
360  }
361  return sent;
362  }
363  else
364  {
366  return -1;
367  }
368 }
369 
370 int
372 {
373  NS_LOG_FUNCTION (this << address << p);
374  if (!m_connected)
375  {
377  return -1;
378  }
379  else
380  {
381  return Send (p, flags); //drop the address according to BSD manpages
382  }
383 }
384 
385 uint32_t
387 {
389  if (m_txBufferSize != 0)
390  {
392  return m_sndBufSize - m_txBufferSize;
393  }
394  else
395  {
396  return m_sndBufSize;
397  }
398 }
399 
400 int
402 {
403  NS_LOG_FUNCTION (this);
405  m_state = LISTEN;
406  return 0;
407 }
408 
409 
410 void
412 {
413  switch (m_state) {
414  case SYN_SENT:
415  if (!m_nscTcpSocket->is_connected ())
416  break;
419  // fall through to schedule read/write events
420  case ESTABLISHED:
421  if (!m_txBuffer.empty ())
424  break;
425  case LISTEN:
427  break;
428  case CLOSED: break;
429  default:
430  NS_LOG_DEBUG (this << " invalid state: " << m_state);
431  }
432 }
433 
435 NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
436 {
438  if (m_deliveryQueue.empty () )
439  {
441  return 0;
442  }
443  Ptr<Packet> p = m_deliveryQueue.front ();
444  if (p->GetSize () <= maxSize)
445  {
446  m_deliveryQueue.pop ();
447  m_rxAvailable -= p->GetSize ();
448  }
449  else
450  {
452  p = 0;
453  }
454  return p;
455 }
456 
458 NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
459  Address &fromAddress)
460 {
461  NS_LOG_FUNCTION (this << maxSize << flags);
462  Ptr<Packet> packet = Recv (maxSize, flags);
463  if (packet != 0)
464  {
465  SocketAddressTag tag;
466  bool found;
467  found = packet->PeekPacketTag (tag);
468  NS_ASSERT (found);
469  fromAddress = tag.GetAddress ();
470  }
471  return packet;
472 }
473 
474 int
476 {
479  return 0;
480 }
481 
482 uint32_t
484 {
486  // We separately maintain this state to avoid walking the queue
487  // every time this might be called
488  return m_rxAvailable;
489 }
490 
491 void
493  Ptr<Ipv4Interface> incomingInterface)
494 {
495  NSCWakeup ();
496 }
497 
499 {
500  // The address pairs (m_localAddress, m_localPort, m_remoteAddress, m_remotePort)
501  // are bogus, but this isn't important at the moment, because
502  // address <-> Socket handling is done by NSC internally.
503  // We only need to add the new ns-3 socket to the list of sockets, so
504  // we use plain Allocate() instead of Allocate(m_localAddress, ... )
505  struct sockaddr_in sin;
506  size_t sin_len = sizeof(sin);
507 
508  if (0 == m_nscTcpSocket->getpeername ((struct sockaddr*) &sin, &sin_len)) {
509  m_remotePort = ntohs (sin.sin_port);
510  m_remoteAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
512  }
513 
514  m_endPoint = m_tcp->Allocate ();
515 
516  //the cloned socket with be in listen state, so manually change state
517  NS_ASSERT (m_state == LISTEN);
519 
520  sin_len = sizeof(sin);
521 
522  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len))
523  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
524 
525  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " accepted connection from "
526  << m_remoteAddress << ":" << m_remotePort
527  << " to " << m_localAddress << ":" << m_localPort);
528  //equivalent to FinishBind
531 
533 }
534 
536 { // We would preferred to have scheduled an event directly to
537  // NotifyConnectionSucceeded, but (sigh) these are protected
538  // and we can get the address of it :(
539  struct sockaddr_in sin;
540  size_t sin_len = sizeof(sin);
541  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len)) {
542  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*)&sin.sin_addr);
543  m_localPort = ntohs (sin.sin_port);
544  }
545 
546  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to "
547  << m_remoteAddress << ":" << m_remotePort
548  << " from " << m_localAddress << ":" << m_localPort);
550 }
551 
552 
554 {
555  if (m_state == CLOSED)
556  { // Happens if application closes listening socket after Accept() was scheduled.
557  return false;
558  }
559  NS_ASSERT (m_state == LISTEN);
560 
561  if (!m_nscTcpSocket->is_listening ())
562  {
563  return false;
564  }
565  INetStreamSocket *newsock;
566  int res = m_nscTcpSocket->accept (&newsock);
567  if (res != 0)
568  {
569  return false;
570  }
571 // We could obtain a fromAddress using getpeername, but we've already
572 // finished the tcp handshake here, i.e. this is a new connection
573 // and not a connection request.
574 // if (!NotifyConnectionRequest(fromAddress))
575 // return true;
576 
577  // Clone the socket
578  Ptr<NscTcpSocketImpl> newSock = Copy ();
579  newSock->m_nscTcpSocket = newsock;
580  NS_LOG_LOGIC ("Cloned a NscTcpSocketImpl " << newSock);
581 
583  return true;
584 }
585 
587 {
588  if (m_state != ESTABLISHED)
589  {
590  return false;
591  }
592  int len, err;
593  uint8_t buffer[8192];
594  len = sizeof(buffer);
596  err = m_nscTcpSocket->read_data (buffer, &len);
597  if (err == 0 && len == 0)
598  {
599  NS_LOG_LOGIC ("ReadPendingData got EOF from socket");
601  return false;
602  }
603  m_errno = GetNativeNs3Errno (err);
604  switch (m_errno)
605  {
606  case ERROR_NOTERROR: break; // some data was sent
607  case ERROR_AGAIN: return false;
608  default:
609  NS_LOG_WARN ("Error (" << err << ") " <<
610  "during read_data, ns-3 errno set to" << m_errno);
611  m_state = CLOSED;
612  return false;
613  }
614 
615  Ptr<Packet> p = Create<Packet> (buffer, len);
616 
617  SocketAddressTag tag;
618 
620  p->AddPacketTag (tag);
621  m_deliveryQueue.push (p);
622  m_rxAvailable += p->GetSize ();
623 
624  NotifyDataRecv ();
625  return true;
626 }
627 
629 {
630  NS_LOG_FUNCTION (this);
631  NS_LOG_LOGIC ("ENTERING SendPendingData");
632 
633  if (m_txBuffer.empty ())
634  {
635  return false;
636  }
637 
638  int ret;
639  size_t size, written = 0;
640 
641  do {
642  NS_ASSERT (!m_txBuffer.empty ());
643  Ptr<Packet> &p = m_txBuffer.front ();
644  size = p->GetSize ();
645  NS_ASSERT (size > 0);
646 
648 
649  uint8_t *buf = new uint8_t[size];
650  p->CopyData (buf, size);
651  ret = m_nscTcpSocket->send_data ((const char *)buf, size);
652  delete[] buf;
653 
654  if (ret <= 0)
655  {
656  break;
657  }
658  written += ret;
659 
660  NS_ASSERT (m_txBufferSize >= (size_t)ret);
661  m_txBufferSize -= ret;
662 
663  if ((size_t)ret < size)
664  {
665  p->RemoveAtStart (ret);
666  break;
667  }
668 
669  m_txBuffer.pop ();
670 
671  if (m_txBuffer.empty ())
672  {
673  if (m_closeOnEmpty)
674  {
676  m_state = CLOSED;
677  }
678  break;
679  }
680  } while ((size_t) ret == size);
681 
682  if (written > 0)
683  {
685  return true;
686  }
687  return false;
688 }
689 
691 {
692  return CopyObject<NscTcpSocketImpl> (this);
693 }
694 
695 void
697 {
698  m_sndBufSize = size;
699 }
700 
701 uint32_t
703 {
704  return m_sndBufSize;
705 }
706 
707 void
709 {
710  m_rcvBufSize = size;
711 }
712 
713 uint32_t
715 {
716  return m_rcvBufSize;
717 }
718 
719 void
721 {
722  m_segmentSize = size;
723 }
724 
725 uint32_t
727 {
728  return m_segmentSize;
729 }
730 
731 void
733 {
735 }
736 
737 uint32_t
739 {
740  return m_advertisedWindowSize;
741 }
742 
743 void
745 {
746  m_initialSsThresh = threshold;
747 }
748 
749 uint32_t
751 {
752  return m_initialSsThresh;
753 }
754 
755 void
757 {
758  m_initialCWnd = cwnd;
759 }
760 
761 uint32_t
763 {
764  return m_initialCWnd;
765 }
766 
767 void
769 {
771 }
772 
773 Time
775 {
776  return m_cnTimeout;
777 }
778 
779 void
781 {
782  m_cnCount = count;
783 }
784 
785 uint32_t
787 {
788  return m_cnCount;
789 }
790 
791 void
793 {
795 }
796 
797 Time
799 {
800  return m_delAckTimeout;
801 }
802 
803 void
805 {
806  m_delAckMaxCount = count;
807 }
808 
809 uint32_t
811 {
812  return m_delAckMaxCount;
813 }
814 
815 void
817 {
818  m_noDelay = noDelay;
819 }
820 
821 bool
823 {
824  return m_noDelay;
825 }
826 
827 void
829 {
831 }
832 
833 Time
835 {
836  return m_persistTimeout;
837 }
838 
841 {
842  enum nsc_errno err;
843 
844  if (error >= 0)
845  {
846  return ERROR_NOTERROR;
847  }
848  err = (enum nsc_errno) error;
849  switch (err)
850  {
851  case NSC_EADDRINUSE: // fallthrough
853  case NSC_EINPROGRESS: // Altough nsc sockets are nonblocking, we pretend they're not.
854  case NSC_EAGAIN: return ERROR_AGAIN;
855  case NSC_EISCONN: // fallthrough
856  case NSC_EALREADY: return ERROR_ISCONN;
858  case NSC_ECONNRESET: // for no, all of these fall through
859  case NSC_EHOSTDOWN:
860  case NSC_ENETUNREACH:
862  case NSC_EMSGSIZE: return ERROR_MSGSIZE;
863  case NSC_ENOTCONN: return ERROR_NOTCONN;
864  case NSC_ESHUTDOWN: return ERROR_SHUTDOWN;
865  case NSC_ETIMEDOUT: return ERROR_NOTCONN;
866  case NSC_ENOTDIR: // used by eg. sysctl(2). Shouldn't happen normally,
867  // but is triggered by e.g. show_config().
868  case NSC_EUNKNOWN: return ERROR_INVAL; // Catches stacks that 'return -1' without real mapping
869  }
870  NS_ASSERT_MSG (0, "Unknown NSC error");
871  return ERROR_INVAL;
872 }
873 
874 bool
876 {
877  if (allowBroadcast)
878  {
879  return false;
880  }
881  return true;
882 }
883 
884 bool
886 {
887  return false;
888 }
889 
890 } // 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:95
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:77
#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 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:304
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:174
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.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:836
void SetAddress(Address addr)
Set the tag's address.
Definition: socket.cc:522
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:61
#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:766
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:858
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:1290
void NotifyDataSent(uint32_t size)
Notify through the callback (if set) that some data have been sent.
Definition: socket.cc:284
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:216
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:274
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:980
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:84
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:15
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:529
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:859
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 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:51
virtual void SetDelAckTimeout(Time timeout)
Set the time to delay an ACK.
uint32_t m_segmentSize
SegmentSize.
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631
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()