A Discrete-Event Network Simulator
API
nsc-tcp-socket-impl.h
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 #ifndef NSC_TCP_SOCKET_IMPL_H
17 #define NSC_TCP_SOCKET_IMPL_H
18 
19 #include <stdint.h>
20 #include <queue>
21 #include <vector>
22 
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"
32 
33 struct INetStreamSocket;
34 
35 namespace ns3 {
36 
37 class Ipv4EndPoint;
38 class Node;
39 class Packet;
40 class NscTcpL4Protocol;
41 class TcpHeader;
42 
54 {
55 public:
60  static TypeId GetTypeId (void);
65 
71  NscTcpSocketImpl (const NscTcpSocketImpl& sock);
72  virtual ~NscTcpSocketImpl ();
73 
78  void SetNode (Ptr<Node> node);
79 
84  void SetTcp (Ptr<NscTcpL4Protocol> tcp);
85 
86  virtual enum SocketErrno GetErrno (void) const;
87  virtual enum SocketType GetSocketType (void) const;
88  virtual int GetPeerName (Address &address) const;
89  virtual Ptr<Node> GetNode (void) const;
90  virtual int Bind (void);
91  virtual int Bind6 (void);
92  virtual int Bind (const Address &address);
93  virtual int Close (void);
94  virtual int ShutdownSend (void);
95  virtual int ShutdownRecv (void);
96  virtual int Connect (const Address &address);
97  virtual int Listen (void);
98  virtual uint32_t GetTxAvailable (void) const;
99  virtual int Send (Ptr<Packet> p, uint32_t flags);
100  virtual int SendTo (Ptr<Packet> p, uint32_t flags, const Address &toAddress);
101  virtual uint32_t GetRxAvailable (void) const;
102  virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
103  virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
104  Address &fromAddress);
105  virtual int GetSockName (Address &address) const;
106  virtual bool SetAllowBroadcast (bool allowBroadcast);
107  virtual bool GetAllowBroadcast () const;
108  virtual void BindToNetDevice (Ptr<NetDevice> netdevice); // NetDevice with my m_endPoint
109 
110 private:
116  void NSCWakeup (void);
121  friend class Tcp;
122  // invoked by Tcp class
127  int FinishBind (void);
136  void ForwardUp (Ptr<Packet> p, Ipv4Header header, uint16_t port,
137  Ptr<Ipv4Interface> incomingInterface);
144  void Destroy (void);
145  //methods for state
150  bool SendPendingData (void);
155  bool ReadPendingData (void);
160  bool Accept (void);
164  void CompleteFork (void);
165 
169  void ConnectionSucceeded ();
170 
171  // Manage data tx/rx
172  // \todo This should be virtual and overridden
178 
179  // attribute related
180  virtual void SetSndBufSize (uint32_t size);
181  virtual uint32_t GetSndBufSize (void) const;
182  virtual void SetRcvBufSize (uint32_t size);
183  virtual uint32_t GetRcvBufSize (void) const;
184  virtual void SetSegSize (uint32_t size);
185  virtual uint32_t GetSegSize (void) const;
190  virtual void SetAdvWin (uint32_t window);
195  virtual uint32_t GetAdvWin (void) const;
196  virtual void SetInitialSSThresh (uint32_t threshold);
197  virtual uint32_t GetInitialSSThresh (void) const;
198  virtual void SetInitialCwnd (uint32_t cwnd);
199  virtual uint32_t GetInitialCwnd (void) const;
200  virtual void SetConnTimeout (Time timeout);
201  virtual Time GetConnTimeout (void) const;
202  virtual uint32_t GetSynRetries (void) const;
203  virtual void SetSynRetries (uint32_t count);
204  virtual void SetDataRetries (uint32_t retries);
205  virtual uint32_t GetDataRetries (void) const;
206  virtual void SetDelAckTimeout (Time timeout);
207  virtual Time GetDelAckTimeout (void) const;
208  virtual void SetDelAckMaxCount (uint32_t count);
209  virtual uint32_t GetDelAckMaxCount (void) const;
210  virtual void SetTcpNoDelay (bool noDelay);
211  virtual bool GetTcpNoDelay (void) const;
212  virtual void SetPersistTimeout (Time timeout);
213  virtual Time GetPersistTimeout (void) const;
214 
220  enum Socket::SocketErrno GetNativeNs3Errno (int err) const;
221  uint32_t m_delAckMaxCount;
223  bool m_noDelay;
224 
229  uint16_t m_remotePort;
230  //these two are so that the socket/endpoint cloning works
232  uint16_t m_localPort;
234  mutable enum SocketErrno m_errno;
237  bool m_connected;
238 
239  //manage the state information
242 
243  //needed to queue data when in SYN_SENT state
244  std::queue<Ptr<Packet> > m_txBuffer;
245  uint32_t m_txBufferSize;
246 
247  // Window management
248  uint32_t m_segmentSize;
249  uint32_t m_rxWindowSize;
253  uint32_t m_initialCWnd;
254  uint32_t m_initialSsThresh;
255 
256  // Round trip time estimation
258 
259  // Timer-related members
261  uint32_t m_synRetries;
262  uint32_t m_dataRetries;
264 
265  // Temporary queue for delivering data to application
266  std::queue<Ptr<Packet> > m_deliveryQueue;
267  uint32_t m_rxAvailable;
269 
270  // Attributes
271  uint32_t m_sndBufSize;
272  uint32_t m_rcvBufSize;
273 };
274 
275 } // namespace ns3
276 
277 #endif /* NSC_TCP_SOCKET_IMPL_H */
Ipv4EndPoint * m_endPoint
the IPv4 endpoint
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
virtual uint32_t GetInitialSSThresh(void) const
Get the initial Slow Start Threshold.
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:47
virtual void SetSndBufSize(uint32_t size)
Set the send buffer size.
uint32_t m_txBufferSize
transmission buffer size
Ipv4Address m_localAddress
local address
NscTcpSocketImpl()
Create an unbound tcp socket.
Ptr< Node > m_node
the associated node
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
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.
virtual uint32_t GetDataRetries(void) const
Get the number of data transmission 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.
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 timeout 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 Time GetConnTimeout(void) const
Get the connection timeout.
SocketErrno
Enumeration of the possible errors returned by a socket.
Definition: socket.h:82
enum Socket::SocketErrno GetNativeNs3Errno(int err) const
Translate between a NSC error and a ns-3 error code.
virtual enum SocketErrno GetErrno(void) const
Get last error number.
uint16_t port
Definition: dsdv-manet.cc:45
a polymophic address class
Definition: address.h:90
bool ReadPendingData(void)
Read all the pending data.
Packet header for IPv4.
Definition: ipv4-header.h:33
Time m_cnTimeout
Timeout for connection retry.
virtual uint32_t GetSndBufSize(void) const
Get the send buffer size.
uint32_t m_initialCWnd
Initial cWnd value.
void SetNode(Ptr< Node > node)
Set the associated node.
enum SocketErrno m_errno
last error number
virtual enum SocketType GetSocketType(void) const
uint32_t m_initialSsThresh
Initial Slow Start Threshold.
virtual void SetTcpNoDelay(bool noDelay)
Enable/Disable Nagle&#39;s algorithm.
virtual uint32_t GetSegSize(void) const
Get the segment size.
bool m_connected
Connection established.
Socket logic for the NSC TCP sockets.
virtual Ptr< Node > GetNode(void) const
Return the node this socket is associated with.
virtual bool SetAllowBroadcast(bool allowBroadcast)
Configure whether broadcast datagram transmissions are allowed.
Time m_persistTimeout
Time between sending 1-byte probes.
virtual uint32_t GetDelAckMaxCount(void) const
Get the number of packet to fire an ACK before delay timeout.
virtual uint32_t GetRxAvailable(void) const
Return number of bytes which can be returned from one or multiple calls to Recv.
virtual int Send(Ptr< Packet > p, uint32_t flags)
Send data (or dummy data) to the remote host.
virtual void BindToNetDevice(Ptr< NetDevice > netdevice)
Bind a socket to specific device.
virtual int ShutdownRecv(void)
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 void SetRcvBufSize(uint32_t size)
Set the receive buffer size.
friend class Tcp
Tcp friend class.
virtual int Listen(void)
Listen for incoming connections.
virtual int Bind(void)
Allocate a local IPv4 endpoint for this socket.
virtual uint32_t GetSynRetries(void) const
Get the number of connection retries before giving up.
virtual Time GetPersistTimeout(void) const
Get the timeout for persistent connection.
void CompleteFork(void)
Complete the Fork operations (after a connection has been accepted)
virtual uint32_t GetAdvWin(void) const
Get the Advertised Window size.
virtual bool GetAllowBroadcast() const
Query whether broadcast datagram transmissions are allowed.
uint16_t m_remotePort
peer port
virtual uint32_t GetTxAvailable(void) const
Returns the number of bytes which can be sent in a single call to Send.
Ptr< NscTcpL4Protocol > m_tcp
the associated TCP L4 protocol
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time m_lastMeasuredRtt
Last measured RTT.
address
Definition: first.py:37
virtual int GetPeerName(Address &address) const
Get the peer address of a connected socket.
virtual uint32_t GetInitialCwnd(void) const
Get the initial Congestion Window.
virtual void SetSegSize(uint32_t size)
Set the segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
bool m_noDelay
Disable ACk delay.
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.
uint32_t m_rxWindowSize
Receive window size.
virtual bool GetTcpNoDelay(void) const
Check if Nagle&#39;s algorithm is enabled or not.
void SetTcp(Ptr< NscTcpL4Protocol > tcp)
Set the associated TCP L4 protocol.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:40
virtual uint32_t GetRcvBufSize(void) const
Get the receive buffer size.
int FinishBind(void)
Finish the binding process.
uint32_t m_delAckMaxCount
Number of packet to fire an ACK before delay timeout.
bool Accept(void)
Accept an incoming connection.
virtual int Close(void)
Close a socket.
void ConnectionSucceeded()
Called when a connection is in Established state.
Struct interface to NSC Stream (i.e., TCP) Sockets.
uint16_t m_localPort
local port
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:58
virtual Time GetDelAckTimeout(void) const
Get the time to delay an ACK.
virtual void SetDelAckTimeout(Time timeout)
Set the time to delay an ACK.
virtual int GetSockName(Address &address) const
Get socket address.
uint32_t m_segmentSize
SegmentSize.
virtual int Connect(const Address &address)
Initiate a connection to a remote host.
A representation of an internet endpoint/connection.
uint32_t m_dataRetries
Count of remaining data retransmission attempts.
void NSCWakeup(void)
Called by NscTcpSocketImpl::ForwardUp()