A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("NscTcpSocketImpl");
47 
48 namespace ns3 {
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  .AddTraceSource ("SlowStartThreshold",
61  "TCP slow start threshold (bytes)",
63  ;
64  return tid;
65 }
66 
68  : m_endPoint (0),
69  m_node (0),
70  m_tcp (0),
71  m_localAddress (Ipv4Address::GetZero ()),
72  m_localPort (0),
73  m_peerAddress ("0.0.0.0", 0),
74  m_errno (ERROR_NOTERROR),
75  m_shutdownSend (false),
76  m_shutdownRecv (false),
77  m_connected (false),
78  m_state (CLOSED),
79  m_closeOnEmpty (false),
80  m_txBufferSize (0),
81  m_lastMeasuredRtt (Seconds (0.0))
82 {
83  NS_LOG_FUNCTION (this);
84 }
85 
87  : TcpSocket (sock), //copy the base class callbacks
88  m_delAckMaxCount (sock.m_delAckMaxCount),
89  m_delAckTimeout (sock.m_delAckTimeout),
90  m_noDelay (sock.m_noDelay),
91  m_endPoint (0),
92  m_node (sock.m_node),
93  m_tcp (sock.m_tcp),
94  m_remoteAddress (sock.m_remoteAddress),
95  m_remotePort (sock.m_remotePort),
96  m_localAddress (sock.m_localAddress),
97  m_localPort (sock.m_localPort),
98  m_peerAddress (sock.m_peerAddress),
99  m_errno (sock.m_errno),
100  m_shutdownSend (sock.m_shutdownSend),
101  m_shutdownRecv (sock.m_shutdownRecv),
102  m_connected (sock.m_connected),
103  m_state (sock.m_state),
104  m_closeOnEmpty (sock.m_closeOnEmpty),
105  m_txBufferSize (sock.m_txBufferSize),
106  m_segmentSize (sock.m_segmentSize),
107  m_rxWindowSize (sock.m_rxWindowSize),
108  m_advertisedWindowSize (sock.m_advertisedWindowSize),
109  m_cWnd (sock.m_cWnd),
110  m_ssThresh (sock.m_ssThresh),
111  m_initialCWnd (sock.m_initialCWnd),
112  m_initialSsThresh (sock.m_initialSsThresh),
113  m_lastMeasuredRtt (Seconds (0.0)),
114  m_cnTimeout (sock.m_cnTimeout),
115  m_cnCount (sock.m_cnCount),
116  m_rxAvailable (0),
117  m_nscTcpSocket (0),
118  m_sndBufSize (sock.m_sndBufSize)
119 {
121  NS_LOG_LOGIC ("Invoked the copy constructor");
122  //copy the pending data if necessary
123  if(!sock.m_txBuffer.empty () )
124  {
125  m_txBuffer = sock.m_txBuffer;
126  }
127  //can't "copy" the endpoint just yes, must do this when we know the peer info
128  //too; this is in SYN_ACK_TX
129 }
130 
132 {
133  NS_LOG_FUNCTION (this);
134  m_node = 0;
135  if (m_endPoint != 0)
136  {
137  NS_ASSERT (m_tcp != 0);
146  NS_ASSERT (m_endPoint != 0);
147  m_tcp->DeAllocate (m_endPoint);
148  NS_ASSERT (m_endPoint == 0);
149  }
150  m_tcp = 0;
151 }
152 
153 void
155 {
156  m_node = node;
157  // Initialize some variables
161 }
162 
163 void
165 {
166  m_nscTcpSocket = tcp->m_nscStack->new_tcp_socket ();
167  m_tcp = tcp;
168 }
169 
170 
173 {
175  return m_errno;
176 }
177 
180 {
181  return NS3_SOCK_STREAM;
182 }
183 
184 Ptr<Node>
186 {
188  return m_node;
189 }
190 
191 void
193 {
195  m_node = 0;
196  m_endPoint = 0;
197  m_tcp = 0;
198 }
199 int
201 {
203  if (m_endPoint == 0)
204  {
205  return -1;
206  }
211  return 0;
212 }
213 
214 int
216 {
218  m_endPoint = m_tcp->Allocate ();
219  return FinishBind ();
220 }
221 int
223 {
224  NS_LOG_LOGIC ("NscTcpSocketImpl: ERROR_AFNOSUPPORT - Bind6 not supported");
226  return (-1);
227 }
228 int
230 {
231  NS_LOG_FUNCTION (this<<address);
232  if (!InetSocketAddress::IsMatchingType (address))
233  {
234  return ERROR_INVAL;
235  }
237  Ipv4Address ipv4 = transport.GetIpv4 ();
238  uint16_t port = transport.GetPort ();
239  if (ipv4 == Ipv4Address::GetAny () && port == 0)
240  {
241  m_endPoint = m_tcp->Allocate ();
242  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
243  }
244  else if (ipv4 == Ipv4Address::GetAny () && port != 0)
245  {
246  m_endPoint = m_tcp->Allocate (port);
247  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
248  }
249  else if (ipv4 != Ipv4Address::GetAny () && port == 0)
250  {
251  m_endPoint = m_tcp->Allocate (ipv4);
252  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
253  }
254  else if (ipv4 != Ipv4Address::GetAny () && port != 0)
255  {
256  m_endPoint = m_tcp->Allocate (ipv4, port);
257  NS_LOG_LOGIC ("NscTcpSocketImpl "<<this<<" got an endpoint: "<<m_endPoint);
258  }
259 
260  m_localPort = port;
261  return FinishBind ();
262 }
263 
264 int
266 {
268  m_shutdownSend = true;
269  return 0;
270 }
271 int
273 {
275  m_shutdownRecv = true;
276  return 0;
277 }
278 
279 int
281 {
282  NS_LOG_FUNCTION (this << m_state);
283 
284  if (m_state == CLOSED)
285  {
286  return -1;
287  }
288  if (!m_txBuffer.empty ())
289  { // App close with pending data must wait until all data transmitted
290  m_closeOnEmpty = true;
291  NS_LOG_LOGIC ("Socket " << this <<
292  " deferring close, state " << m_state);
293  return 0;
294  }
295 
296  NS_LOG_LOGIC ("NscTcp socket " << this << " calling disconnect(); moving to CLOSED");
298  m_state = CLOSED;
299  ShutdownSend ();
300  return 0;
301 }
302 
303 int
305 {
306  NS_LOG_FUNCTION (this << address);
307  if (m_endPoint == 0)
308  {
309  if (Bind () == -1)
310  {
311  NS_ASSERT (m_endPoint == 0);
312  return -1;
313  }
314  NS_ASSERT (m_endPoint != 0);
315  }
317  m_remoteAddress = transport.GetIpv4 ();
318  m_remotePort = transport.GetPort ();
319 
320  std::ostringstream ss;
321  m_remoteAddress.Print (ss);
322  std::string ipstring = ss.str ();
323 
324  m_nscTcpSocket->connect (ipstring.c_str (), m_remotePort);
325  m_state = SYN_SENT;
326  return 0;
327 }
328 
329 int
330 NscTcpSocketImpl::Send (const Ptr<Packet> p, uint32_t flags)
331 {
332  NS_LOG_FUNCTION (this << p);
333 
334  NS_ASSERT (p->GetSize () > 0);
336  {
337  if (p->GetSize () > GetTxAvailable ())
338  {
340  return -1;
341  }
342 
343  uint32_t sent = p->GetSize ();
344  if (m_state == ESTABLISHED)
345  {
346  m_txBuffer.push (p);
347  m_txBufferSize += sent;
348  SendPendingData ();
349  }
350  else
351  { // SYN_SET -- Queue Data
352  m_txBuffer.push (p);
353  m_txBufferSize += sent;
354  }
355  return sent;
356  }
357  else
358  {
360  return -1;
361  }
362 }
363 
364 int
366 {
367  NS_LOG_FUNCTION (this << address << p);
368  if (!m_connected)
369  {
371  return -1;
372  }
373  else
374  {
375  return Send (p, flags); //drop the address according to BSD manpages
376  }
377 }
378 
379 uint32_t
381 {
383  if (m_txBufferSize != 0)
384  {
386  return m_sndBufSize - m_txBufferSize;
387  }
388  else
389  {
390  return m_sndBufSize;
391  }
392 }
393 
394 int
396 {
397  NS_LOG_FUNCTION (this);
399  m_state = LISTEN;
400  return 0;
401 }
402 
403 
404 void
406 {
407  switch (m_state) {
408  case SYN_SENT:
409  if (!m_nscTcpSocket->is_connected ())
410  break;
413  // fall through to schedule read/write events
414  case ESTABLISHED:
415  if (!m_txBuffer.empty ())
418  break;
419  case LISTEN:
421  break;
422  case CLOSED: break;
423  default:
424  NS_LOG_DEBUG (this << " invalid state: " << m_state);
425  }
426 }
427 
429 NscTcpSocketImpl::Recv (uint32_t maxSize, uint32_t flags)
430 {
432  if (m_deliveryQueue.empty () )
433  {
435  return 0;
436  }
437  Ptr<Packet> p = m_deliveryQueue.front ();
438  if (p->GetSize () <= maxSize)
439  {
440  m_deliveryQueue.pop ();
441  m_rxAvailable -= p->GetSize ();
442  }
443  else
444  {
446  p = 0;
447  }
448  return p;
449 }
450 
452 NscTcpSocketImpl::RecvFrom (uint32_t maxSize, uint32_t flags,
453  Address &fromAddress)
454 {
455  NS_LOG_FUNCTION (this << maxSize << flags);
456  Ptr<Packet> packet = Recv (maxSize, flags);
457  if (packet != 0)
458  {
459  SocketAddressTag tag;
460  bool found;
461  found = packet->PeekPacketTag (tag);
462  NS_ASSERT (found);
463  fromAddress = tag.GetAddress ();
464  }
465  return packet;
466 }
467 
468 int
470 {
473  return 0;
474 }
475 
476 uint32_t
478 {
480  // We separately maintain this state to avoid walking the queue
481  // every time this might be called
482  return m_rxAvailable;
483 }
484 
485 void
487  Ptr<Ipv4Interface> incomingInterface)
488 {
489  NSCWakeup ();
490 }
491 
493 {
494  // The address pairs (m_localAddress, m_localPort, m_remoteAddress, m_remotePort)
495  // are bogus, but this isn't important at the moment, because
496  // address <-> Socket handling is done by NSC internally.
497  // We only need to add the new ns-3 socket to the list of sockets, so
498  // we use plain Allocate() instead of Allocate(m_localAddress, ... )
499  struct sockaddr_in sin;
500  size_t sin_len = sizeof(sin);
501 
502  if (0 == m_nscTcpSocket->getpeername ((struct sockaddr*) &sin, &sin_len)) {
503  m_remotePort = ntohs (sin.sin_port);
504  m_remoteAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
506  }
507 
508  m_endPoint = m_tcp->Allocate ();
509 
510  //the cloned socket with be in listen state, so manually change state
511  NS_ASSERT (m_state == LISTEN);
513 
514  sin_len = sizeof(sin);
515 
516  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len))
517  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*) &sin.sin_addr);
518 
519  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " accepted connection from "
520  << m_remoteAddress << ":" << m_remotePort
521  << " to " << m_localAddress << ":" << m_localPort);
522  //equivalent to FinishBind
525 
527 }
528 
530 { // We would preferred to have scheduled an event directly to
531  // NotifyConnectionSucceeded, but (sigh) these are protected
532  // and we can get the address of it :(
533  struct sockaddr_in sin;
534  size_t sin_len = sizeof(sin);
535  if (0 == m_nscTcpSocket->getsockname ((struct sockaddr *) &sin, &sin_len)) {
536  m_localAddress = Ipv4Address::Deserialize ((const uint8_t*)&sin.sin_addr);
537  m_localPort = ntohs (sin.sin_port);
538  }
539 
540  NS_LOG_LOGIC ("NscTcpSocketImpl " << this << " connected to "
541  << m_remoteAddress << ":" << m_remotePort
542  << " from " << m_localAddress << ":" << m_localPort);
544 }
545 
546 
548 {
549  if (m_state == CLOSED)
550  { // Happens if application closes listening socket after Accept() was scheduled.
551  return false;
552  }
553  NS_ASSERT (m_state == LISTEN);
554 
555  if (!m_nscTcpSocket->is_listening ())
556  {
557  return false;
558  }
559  INetStreamSocket *newsock;
560  int res = m_nscTcpSocket->accept (&newsock);
561  if (res != 0)
562  {
563  return false;
564  }
565 // We could obtain a fromAddress using getpeername, but we've already
566 // finished the tcp handshake here, i.e. this is a new connection
567 // and not a connection request.
568 // if (!NotifyConnectionRequest(fromAddress))
569 // return true;
570 
571  // Clone the socket
572  Ptr<NscTcpSocketImpl> newSock = Copy ();
573  newSock->m_nscTcpSocket = newsock;
574  NS_LOG_LOGIC ("Cloned a NscTcpSocketImpl " << newSock);
575 
577  return true;
578 }
579 
581 {
582  if (m_state != ESTABLISHED)
583  {
584  return false;
585  }
586  int len, err;
587  uint8_t buffer[8192];
588  len = sizeof(buffer);
590  err = m_nscTcpSocket->read_data (buffer, &len);
591  if (err == 0 && len == 0)
592  {
593  NS_LOG_LOGIC ("ReadPendingData got EOF from socket");
595  return false;
596  }
597  m_errno = GetNativeNs3Errno (err);
598  switch (m_errno)
599  {
600  case ERROR_NOTERROR: break; // some data was sent
601  case ERROR_AGAIN: return false;
602  default:
603  NS_LOG_WARN ("Error (" << err << ") " <<
604  "during read_data, ns-3 errno set to" << m_errno);
605  m_state = CLOSED;
606  return false;
607  }
608 
609  Ptr<Packet> p = Create<Packet> (buffer, len);
610 
611  SocketAddressTag tag;
612 
614  p->AddPacketTag (tag);
615  m_deliveryQueue.push (p);
616  m_rxAvailable += p->GetSize ();
617 
618  NotifyDataRecv ();
619  return true;
620 }
621 
623 {
624  NS_LOG_FUNCTION (this);
625  NS_LOG_LOGIC ("ENTERING SendPendingData");
626 
627  if (m_txBuffer.empty ())
628  {
629  return false;
630  }
631 
632  int ret;
633  size_t size, written = 0;
634 
635  do {
636  NS_ASSERT (!m_txBuffer.empty ());
637  Ptr<Packet> &p = m_txBuffer.front ();
638  size = p->GetSize ();
639  NS_ASSERT (size > 0);
640 
642 
643  uint8_t *buf = new uint8_t[size];
644  p->CopyData (buf, size);
645  ret = m_nscTcpSocket->send_data ((const char *)buf, size);
646  delete[] buf;
647 
648  if (ret <= 0)
649  {
650  break;
651  }
652  written += ret;
653 
654  NS_ASSERT (m_txBufferSize >= (size_t)ret);
655  m_txBufferSize -= ret;
656 
657  if ((size_t)ret < size)
658  {
659  p->RemoveAtStart (ret);
660  break;
661  }
662 
663  m_txBuffer.pop ();
664 
665  if (m_txBuffer.empty ())
666  {
667  if (m_closeOnEmpty)
668  {
670  m_state = CLOSED;
671  }
672  break;
673  }
674  } while ((size_t) ret == size);
675 
676  if (written > 0)
677  {
679  return true;
680  }
681  return false;
682 }
683 
685 {
686  return CopyObject<NscTcpSocketImpl> (this);
687 }
688 
689 void
691 {
692  m_sndBufSize = size;
693 }
694 
695 uint32_t
697 {
698  return m_sndBufSize;
699 }
700 
701 void
703 {
704  m_rcvBufSize = size;
705 }
706 
707 uint32_t
709 {
710  return m_rcvBufSize;
711 }
712 
713 void
715 {
716  m_segmentSize = size;
717 }
718 
719 uint32_t
721 {
722  return m_segmentSize;
723 }
724 
725 void
727 {
729 }
730 
731 uint32_t
733 {
734  return m_advertisedWindowSize;
735 }
736 
737 void
739 {
740  m_initialSsThresh = threshold;
741 }
742 
743 uint32_t
745 {
746  return m_initialSsThresh;
747 }
748 
749 void
751 {
752  m_initialCWnd = cwnd;
753 }
754 
755 uint32_t
757 {
758  return m_initialCWnd;
759 }
760 
761 void
763 {
765 }
766 
767 Time
769 {
770  return m_cnTimeout;
771 }
772 
773 void
775 {
776  m_cnCount = count;
777 }
778 
779 uint32_t
781 {
782  return m_cnCount;
783 }
784 
785 void
787 {
789 }
790 
791 Time
793 {
794  return m_delAckTimeout;
795 }
796 
797 void
799 {
800  m_delAckMaxCount = count;
801 }
802 
803 uint32_t
805 {
806  return m_delAckMaxCount;
807 }
808 
809 void
811 {
812  m_noDelay = noDelay;
813 }
814 
815 bool
817 {
818  return m_noDelay;
819 }
820 
821 void
823 {
825 }
826 
827 Time
829 {
830  return m_persistTimeout;
831 }
832 
835 {
836  enum nsc_errno err;
837 
838  if (error >= 0)
839  {
840  return ERROR_NOTERROR;
841  }
842  err = (enum nsc_errno) error;
843  switch (err)
844  {
845  case NSC_EADDRINUSE: // fallthrough
847  case NSC_EINPROGRESS: // Altough nsc sockets are nonblocking, we pretend they're not.
848  case NSC_EAGAIN: return ERROR_AGAIN;
849  case NSC_EISCONN: // fallthrough
850  case NSC_EALREADY: return ERROR_ISCONN;
852  case NSC_ECONNRESET: // for no, all of these fall through
853  case NSC_EHOSTDOWN:
854  case NSC_ENETUNREACH:
856  case NSC_EMSGSIZE: return ERROR_MSGSIZE;
857  case NSC_ENOTCONN: return ERROR_NOTCONN;
858  case NSC_ESHUTDOWN: return ERROR_SHUTDOWN;
859  case NSC_ETIMEDOUT: return ERROR_NOTCONN;
860  case NSC_ENOTDIR: // used by eg. sysctl(2). Shouldn't happen normally,
861  // but is triggered by e.g. show_config().
862  case NSC_EUNKNOWN: return ERROR_INVAL; // Catches stacks that 'return -1' without real mapping
863  }
864  NS_ASSERT_MSG (0, "Unknown NSC error");
865  return ERROR_INVAL;
866 }
867 
868 bool
870 {
871  if (allowBroadcast)
872  {
873  return false;
874  }
875  return true;
876 }
877 
878 bool
880 {
881  return false;
882 }
883 
884 } // 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 "...
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:64
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
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:841
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:170
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:744
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.
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.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
uint16_t port
Definition: dsdv-manet.cc:44
a polymophic address class
Definition: address.h:86
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:863
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:1283
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:233
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
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
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
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:986
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:38
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:203
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:213
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:845
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.
SocketType
Enumeration of the possible socket types.
Definition: socket.h:104
a unique identifier for an interface.
Definition: type-id.h:49
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:610
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()