A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
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  */
19 #include <stdint.h>
20 #include <queue>
21 #include <vector>
23 #include "ns3/callback.h"
24 #include "ns3/traced-value.h"
25 #include "ns3/tcp-socket.h"
26 #include "ns3/ptr.h"
27 #include "ns3/ipv4-address.h"
28 #include "ns3/inet-socket-address.h"
29 #include "ns3/event-id.h"
30 #include "pending-data.h"
31 #include "ns3/sequence-number.h"
33 struct INetStreamSocket;
35 namespace ns3 {
37 class Ipv4EndPoint;
38 class Node;
39 class Packet;
40 class NscTcpL4Protocol;
41 class TcpHeader;
54 {
55 public:
60  static TypeId GetTypeId (void);
71  NscTcpSocketImpl (const NscTcpSocketImpl& sock);
72  virtual ~NscTcpSocketImpl ();
78  void SetNode (Ptr<Node> node);
84  void SetTcp (Ptr<NscTcpL4Protocol> tcp);
86  virtual enum SocketErrno GetErrno (void) const;
87  virtual enum SocketType GetSocketType (void) const;
88  virtual Ptr<Node> GetNode (void) const;
89  virtual int Bind (void);
90  virtual int Bind6 (void);
91  virtual int Bind (const Address &address);
92  virtual int Close (void);
93  virtual int ShutdownSend (void);
94  virtual int ShutdownRecv (void);
95  virtual int Connect (const Address &address);
96  virtual int Listen (void);
97  virtual uint32_t GetTxAvailable (void) const;
98  virtual int Send (Ptr<Packet> p, uint32_t flags);
99  virtual int SendTo (Ptr<Packet> p, uint32_t flags, const Address &toAddress);
100  virtual uint32_t GetRxAvailable (void) const;
101  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
102  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
103  Address &fromAddress);
104  virtual int GetSockName (Address &address) const;
105  virtual bool SetAllowBroadcast (bool allowBroadcast);
106  virtual bool GetAllowBroadcast () const;
108 private:
114  void NSCWakeup (void);
115  friend class Tcp;
116  // invoked by Tcp class
121  int FinishBind (void);
130  void ForwardUp (Ptr<Packet> p, Ipv4Header header, uint16_t port,
131  Ptr<Ipv4Interface> incomingInterface);
138  void Destroy (void);
139  //methods for state
144  bool SendPendingData (void);
149  bool ReadPendingData (void);
154  bool Accept (void);
158  void CompleteFork (void);
163  void ConnectionSucceeded ();
165  // Manage data tx/rx
166  // \todo This should be virtual and overridden
173  // attribute related
174  virtual void SetSndBufSize (uint32_t size);
175  virtual uint32_t GetSndBufSize (void) const;
176  virtual void SetRcvBufSize (uint32_t size);
177  virtual uint32_t GetRcvBufSize (void) const;
178  virtual void SetSegSize (uint32_t size);
179  virtual uint32_t GetSegSize (void) const;
184  virtual void SetAdvWin (uint32_t window);
189  virtual uint32_t GetAdvWin (void) const;
190  virtual void SetSSThresh (uint32_t threshold);
191  virtual uint32_t GetSSThresh (void) const;
192  virtual void SetInitialCwnd (uint32_t cwnd);
193  virtual uint32_t GetInitialCwnd (void) const;
194  virtual void SetConnTimeout (Time timeout);
195  virtual Time GetConnTimeout (void) const;
196  virtual void SetConnCount (uint32_t count);
197  virtual uint32_t GetConnCount (void) const;
198  virtual void SetDelAckTimeout (Time timeout);
199  virtual Time GetDelAckTimeout (void) const;
200  virtual void SetDelAckMaxCount (uint32_t count);
201  virtual uint32_t GetDelAckMaxCount (void) const;
202  virtual void SetTcpNoDelay (bool noDelay);
203  virtual bool GetTcpNoDelay (void) const;
204  virtual void SetPersistTimeout (Time timeout);
205  virtual Time GetPersistTimeout (void) const;
212  enum Socket::SocketErrno GetNativeNs3Errno (int err) const;
213  uint32_t m_delAckMaxCount;
215  bool m_noDelay;
221  uint16_t m_remotePort;
222  //these two are so that the socket/endpoint cloning works
224  uint16_t m_localPort;
229  bool m_connected;
231  //manage the state information
235  //needed to queue data when in SYN_SENT state
236  std::queue<Ptr<Packet> > m_txBuffer;
237  uint32_t m_txBufferSize;
239  // Window management
240  uint32_t m_segmentSize;
241  uint32_t m_rxWindowSize;
244  uint32_t m_ssThresh;
245  uint32_t m_initialCWnd;
247  // Round trip time estimation
250  // Timer-related members
252  uint32_t m_cnCount;
255  // Temporary queue for delivering data to application
256  std::queue<Ptr<Packet> > m_deliveryQueue;
257  uint32_t m_rxAvailable;
260  // Attributes
261  uint32_t m_sndBufSize;
262  uint32_t m_rcvBufSize;
263 };
265 } // namespace ns3
267 #endif /* NSC_TCP_SOCKET_IMPL_H */
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
an Inet address class
virtual int ShutdownSend(void)
std::queue< Ptr< Packet > > m_deliveryQueue
receive buffer
void Destroy(void)
Kill this socket by zeroing its attributes (IPv4)
(abstract) base class of all TcpSockets
Definition: tcp-socket.h:64
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
Create an unbound tcp socket.
Ptr< Node > m_node
the associated node
virtual uint32_t GetAdvWin(void) const
Get the Advertised Window size.
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
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 uint32_t GetConnCount(void) const
Get the number of connection retries before giving up.
INetStreamSocket * m_nscTcpSocket
the real NSC TCP socket
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
static TypeId GetTypeId(void)
Get the type ID.
virtual void SetConnTimeout(Time timeout)
Set the connection timeout.
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
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.
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
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.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
Time m_persistTimeout
Time between sending 1-byte probes.
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.
virtual int ShutdownRecv(void)
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
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 Ptr< Packet > RecvFrom(uint32_t maxSize, uint32_t flags, Address &fromAddress)
Read a single packet from the socket and retrieve the sender address.
virtual uint32_t GetSSThresh(void) const
Get the Slow Start Threshold.
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 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
Time m_lastMeasuredRtt
Last measured RTT.
virtual void SetSegSize(uint32_t size)
Set the segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
bool m_noDelay
Disable ACk delay.
uint32_t m_ssThresh
Slow Start Threshold.
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.
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.
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.
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.
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.
uint32_t m_advertisedWindowSize
Window to advertise.
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
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
A representation of an internet endpoint/connection.
virtual void SetSSThresh(uint32_t threshold)
Set the Slow Start Threshold.
virtual uint32_t GetInitialCwnd(void) const
Get the initial Congestion Window.
void NSCWakeup(void)
Called by NscTcpSocketImpl::ForwardUp()