|
fw@3578
|
1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
|
fw@3578
|
2 |
/*
|
|
fw@3578
|
3 |
* This program is free software; you can redistribute it and/or modify
|
|
fw@3578
|
4 |
* it under the terms of the GNU General Public License version 2 as
|
|
fw@3578
|
5 |
* published by the Free Software Foundation;
|
|
fw@3578
|
6 |
*
|
|
fw@3578
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
fw@3578
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
fw@3578
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
fw@3578
|
10 |
* GNU General Public License for more details.
|
|
fw@3578
|
11 |
*
|
|
fw@3578
|
12 |
* You should have received a copy of the GNU General Public License
|
|
fw@3578
|
13 |
* along with this program; if not, write to the Free Software
|
|
fw@3578
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
fw@3578
|
15 |
*/
|
|
fw@3578
|
16 |
#ifndef NSC_TCP_SOCKET_IMPL_H
|
|
fw@3578
|
17 |
#define NSC_TCP_SOCKET_IMPL_H
|
|
fw@3578
|
18 |
|
|
fw@3578
|
19 |
#include <stdint.h>
|
|
fw@3578
|
20 |
#include <queue>
|
|
fw@3578
|
21 |
#include <vector>
|
|
fw@3578
|
22 |
|
|
fw@3578
|
23 |
#include "ns3/callback.h"
|
|
fw@3578
|
24 |
#include "ns3/traced-value.h"
|
|
fw@3578
|
25 |
#include "ns3/tcp-socket.h"
|
|
fw@3578
|
26 |
#include "ns3/ptr.h"
|
|
fw@3578
|
27 |
#include "ns3/ipv4-address.h"
|
|
fw@3578
|
28 |
#include "ns3/inet-socket-address.h"
|
|
fw@3578
|
29 |
#include "ns3/event-id.h"
|
|
fw@3578
|
30 |
#include "tcp-typedefs.h"
|
|
fw@3578
|
31 |
#include "pending-data.h"
|
|
fw@3578
|
32 |
#include "sequence-number.h"
|
|
fw@3578
|
33 |
#include "rtt-estimator.h"
|
|
fw@3578
|
34 |
|
|
fw@4685
|
35 |
class INetStreamSocket;
|
|
fw@3578
|
36 |
namespace ns3 {
|
|
fw@3578
|
37 |
|
|
fw@3578
|
38 |
class Ipv4EndPoint;
|
|
fw@3578
|
39 |
class Node;
|
|
fw@3578
|
40 |
class Packet;
|
|
fw@3578
|
41 |
class NscTcpL4Protocol;
|
|
fw@3578
|
42 |
class TcpHeader;
|
|
fw@3578
|
43 |
|
|
tomh@3691
|
44 |
/**
|
|
tomh@3691
|
45 |
* \ingroup socket
|
|
tomh@3691
|
46 |
* \ingroup nsctcp
|
|
tomh@3691
|
47 |
*
|
|
tomh@3691
|
48 |
* \brief Socket logic for the NSC TCP sockets.
|
|
tomh@3691
|
49 |
*
|
|
tomh@3691
|
50 |
* Most of the TCP internal
|
|
tomh@3691
|
51 |
* logic is handled by the NSC tcp library itself; this class maps ns3::Socket
|
|
tomh@3691
|
52 |
* calls to the NSC TCP library.
|
|
tomh@3691
|
53 |
*/
|
|
fw@3578
|
54 |
class NscTcpSocketImpl : public TcpSocket
|
|
fw@3578
|
55 |
{
|
|
fw@3578
|
56 |
public:
|
|
fw@3578
|
57 |
static TypeId GetTypeId (void);
|
|
fw@3578
|
58 |
/**
|
|
fw@3578
|
59 |
* Create an unbound tcp socket.
|
|
fw@3578
|
60 |
*/
|
|
fw@3578
|
61 |
NscTcpSocketImpl ();
|
|
fw@3578
|
62 |
NscTcpSocketImpl (const NscTcpSocketImpl& sock);
|
|
fw@3578
|
63 |
virtual ~NscTcpSocketImpl ();
|
|
fw@3578
|
64 |
|
|
fw@3578
|
65 |
void SetNode (Ptr<Node> node);
|
|
fw@3578
|
66 |
void SetTcp (Ptr<NscTcpL4Protocol> tcp);
|
|
fw@3578
|
67 |
void SetRtt (Ptr<RttEstimator> rtt);
|
|
fw@3578
|
68 |
|
|
fw@3578
|
69 |
virtual enum SocketErrno GetErrno (void) const;
|
|
fw@3578
|
70 |
virtual Ptr<Node> GetNode (void) const;
|
|
fw@3578
|
71 |
virtual int Bind (void);
|
|
fw@3578
|
72 |
virtual int Bind (const Address &address);
|
|
fw@3578
|
73 |
virtual int Close (void);
|
|
fw@3578
|
74 |
virtual int ShutdownSend (void);
|
|
fw@3578
|
75 |
virtual int ShutdownRecv (void);
|
|
fw@3578
|
76 |
virtual int Connect(const Address &address);
|
|
craigdo@3772
|
77 |
virtual int Listen(void);
|
|
fw@3578
|
78 |
virtual uint32_t GetTxAvailable (void) const;
|
|
fw@3578
|
79 |
virtual int Send (Ptr<Packet> p, uint32_t flags);
|
|
fw@3578
|
80 |
virtual int SendTo(Ptr<Packet> p, uint32_t flags, const Address &toAddress);
|
|
fw@3578
|
81 |
virtual uint32_t GetRxAvailable (void) const;
|
|
fw@3578
|
82 |
virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags);
|
|
fw@3578
|
83 |
virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags,
|
|
fw@3578
|
84 |
Address &fromAddress);
|
|
craigdo@3778
|
85 |
virtual int GetSockName (Address &address) const;
|
|
fw@3578
|
86 |
|
|
fw@3578
|
87 |
private:
|
|
fw@3578
|
88 |
void NSCWakeup(void);
|
|
fw@3578
|
89 |
friend class Tcp;
|
|
fw@3578
|
90 |
// invoked by Tcp class
|
|
fw@3578
|
91 |
int FinishBind (void);
|
|
fw@3578
|
92 |
void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port);
|
|
fw@3578
|
93 |
void Destroy (void);
|
|
fw@3578
|
94 |
//methods for state
|
|
fw@3578
|
95 |
bool SendPendingData(void);
|
|
fw@3578
|
96 |
bool ReadPendingData(void);
|
|
fw@3578
|
97 |
bool Accept(void);
|
|
fw@3578
|
98 |
void CompleteFork(void);
|
|
fw@3578
|
99 |
void ConnectionSucceeded();
|
|
fw@3578
|
100 |
|
|
fw@3578
|
101 |
// Manage data tx/rx
|
|
fw@3578
|
102 |
// XXX This should be virtual and overridden
|
|
fw@3578
|
103 |
Ptr<NscTcpSocketImpl> Copy ();
|
|
fw@3578
|
104 |
|
|
fw@3578
|
105 |
// attribute related
|
|
fw@3578
|
106 |
virtual void SetSndBufSize (uint32_t size);
|
|
fw@3578
|
107 |
virtual uint32_t GetSndBufSize (void) const;
|
|
fw@3578
|
108 |
virtual void SetRcvBufSize (uint32_t size);
|
|
fw@3578
|
109 |
virtual uint32_t GetRcvBufSize (void) const;
|
|
fw@3578
|
110 |
virtual void SetSegSize (uint32_t size);
|
|
fw@3578
|
111 |
virtual uint32_t GetSegSize (void) const;
|
|
fw@3578
|
112 |
virtual void SetAdvWin (uint32_t window);
|
|
fw@3578
|
113 |
virtual uint32_t GetAdvWin (void) const;
|
|
fw@3578
|
114 |
virtual void SetSSThresh (uint32_t threshold);
|
|
fw@3578
|
115 |
virtual uint32_t GetSSThresh (void) const;
|
|
fw@3578
|
116 |
virtual void SetInitialCwnd (uint32_t cwnd);
|
|
fw@3578
|
117 |
virtual uint32_t GetInitialCwnd (void) const;
|
|
fw@3578
|
118 |
virtual void SetConnTimeout (Time timeout);
|
|
fw@3578
|
119 |
virtual Time GetConnTimeout (void) const;
|
|
fw@3578
|
120 |
virtual void SetConnCount (uint32_t count);
|
|
fw@3578
|
121 |
virtual uint32_t GetConnCount (void) const;
|
|
fw@3578
|
122 |
virtual void SetDelAckTimeout (Time timeout);
|
|
fw@3578
|
123 |
virtual Time GetDelAckTimeout (void) const;
|
|
fw@3578
|
124 |
virtual void SetDelAckMaxCount (uint32_t count);
|
|
fw@3578
|
125 |
virtual uint32_t GetDelAckMaxCount (void) const;
|
|
fw@3578
|
126 |
|
|
fw@3578
|
127 |
enum Socket::SocketErrno GetNativeNs3Errno(int err) const;
|
|
fw@3578
|
128 |
uint32_t m_delAckMaxCount;
|
|
fw@3578
|
129 |
Time m_delAckTimeout;
|
|
fw@3578
|
130 |
|
|
fw@3578
|
131 |
Ipv4EndPoint *m_endPoint;
|
|
fw@3578
|
132 |
Ptr<Node> m_node;
|
|
fw@3578
|
133 |
Ptr<NscTcpL4Protocol> m_tcp;
|
|
fw@3578
|
134 |
Ipv4Address m_remoteAddress;
|
|
fw@3578
|
135 |
uint16_t m_remotePort;
|
|
fw@3578
|
136 |
//these two are so that the socket/endpoint cloning works
|
|
fw@3578
|
137 |
Ipv4Address m_localAddress;
|
|
fw@3578
|
138 |
uint16_t m_localPort;
|
|
fw@3578
|
139 |
InetSocketAddress m_peerAddress;
|
|
fw@3578
|
140 |
enum SocketErrno m_errno;
|
|
fw@3578
|
141 |
bool m_shutdownSend;
|
|
fw@3578
|
142 |
bool m_shutdownRecv;
|
|
fw@3578
|
143 |
bool m_connected;
|
|
fw@3578
|
144 |
|
|
fw@3578
|
145 |
//manage the state infomation
|
|
fw@3578
|
146 |
States_t m_state;
|
|
fw@3578
|
147 |
bool m_closeOnEmpty;
|
|
fw@3578
|
148 |
|
|
fw@3578
|
149 |
//needed to queue data when in SYN_SENT state
|
|
fw@3578
|
150 |
std::queue<Ptr<Packet> > m_txBuffer;
|
|
fw@3578
|
151 |
uint32_t m_txBufferSize;
|
|
fw@3578
|
152 |
|
|
fw@3578
|
153 |
// Window management
|
|
fw@3578
|
154 |
uint32_t m_segmentSize; //SegmentSize
|
|
fw@3578
|
155 |
uint32_t m_rxWindowSize;
|
|
fw@3578
|
156 |
uint32_t m_advertisedWindowSize; //Window to advertise
|
|
fw@3578
|
157 |
TracedValue<uint32_t> m_cWnd; //Congestion window
|
|
fw@3578
|
158 |
uint32_t m_ssThresh; //Slow Start Threshold
|
|
fw@3578
|
159 |
uint32_t m_initialCWnd; //Initial cWnd value
|
|
fw@3578
|
160 |
|
|
fw@3578
|
161 |
// Round trip time estimation
|
|
fw@3578
|
162 |
Ptr<RttEstimator> m_rtt;
|
|
fw@3578
|
163 |
Time m_lastMeasuredRtt;
|
|
fw@3578
|
164 |
|
|
fw@3578
|
165 |
// Timer-related members
|
|
fw@3578
|
166 |
Time m_cnTimeout;
|
|
fw@3578
|
167 |
uint32_t m_cnCount;
|
|
fw@3578
|
168 |
|
|
fw@3578
|
169 |
// Temporary queue for delivering data to application
|
|
fw@3578
|
170 |
std::queue<Ptr<Packet> > m_deliveryQueue;
|
|
fw@3578
|
171 |
uint32_t m_rxAvailable;
|
|
fw@3578
|
172 |
INetStreamSocket* m_nscTcpSocket;
|
|
fw@3578
|
173 |
|
|
fw@3578
|
174 |
// Attributes
|
|
fw@3578
|
175 |
uint32_t m_sndBufSize; // buffer limit for the outgoing queue
|
|
fw@3578
|
176 |
uint32_t m_rcvBufSize; // maximum receive socket buffer size
|
|
fw@3578
|
177 |
};
|
|
fw@3578
|
178 |
|
|
fw@3578
|
179 |
}//namespace ns3
|
|
fw@3578
|
180 |
|
|
fw@3578
|
181 |
#endif /* NSC_TCP_SOCKET_IMPL_H */
|