|
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
|
2 /* |
|
3 * Copyright (c) 2007 Georgia Tech Research Corporation |
|
4 * |
|
5 * This program is free software; you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License version 2 as |
|
7 * published by the Free Software Foundation; |
|
8 * |
|
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU General Public License for more details. |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License |
|
15 * along with this program; if not, write to the Free Software |
|
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
17 * |
|
18 * Author: Raj Bhattacharjea <raj.b@gatech.edu> |
|
19 */ |
|
20 #ifndef TCP_SOCKET_IMPL_H |
|
21 #define TCP_SOCKET_IMPL_H |
|
22 |
|
23 #include <stdint.h> |
|
24 #include <queue> |
|
25 #include "ns3/callback.h" |
|
26 #include "ns3/traced-value.h" |
|
27 #include "ns3/tcp-socket.h" |
|
28 #include "ns3/ptr.h" |
|
29 #include "ns3/ipv4-address.h" |
|
30 #include "ns3/event-id.h" |
|
31 #include "tcp-typedefs.h" |
|
32 #include "pending-data.h" |
|
33 #include "sequence-number.h" |
|
34 #include "rtt-estimator.h" |
|
35 |
|
36 |
|
37 namespace ns3 { |
|
38 |
|
39 class Ipv4EndPoint; |
|
40 class Node; |
|
41 class Packet; |
|
42 class TcpL4Protocol; |
|
43 class TcpHeader; |
|
44 |
|
45 class TcpSocketImpl : public TcpSocket |
|
46 { |
|
47 public: |
|
48 static TypeId GetTypeId (void); |
|
49 /** |
|
50 * Create an unbound tcp socket. |
|
51 */ |
|
52 TcpSocketImpl (); |
|
53 TcpSocketImpl (const TcpSocketImpl& sock); |
|
54 virtual ~TcpSocketImpl (); |
|
55 |
|
56 void SetNode (Ptr<Node> node); |
|
57 void SetTcp (Ptr<TcpL4Protocol> tcp); |
|
58 void SetRtt (Ptr<RttEstimator> rtt); |
|
59 |
|
60 virtual enum SocketErrno GetErrno (void) const; |
|
61 virtual Ptr<Node> GetNode (void) const; |
|
62 virtual int Bind (void); |
|
63 virtual int Bind (const Address &address); |
|
64 virtual int Close (void); |
|
65 virtual int ShutdownSend (void); |
|
66 virtual int ShutdownRecv (void); |
|
67 virtual int Connect(const Address &address); |
|
68 virtual int Send (Ptr<Packet> p); |
|
69 virtual int Send (const uint8_t* buf, uint32_t size); |
|
70 virtual int SendTo(Ptr<Packet> p, const Address &address); |
|
71 virtual uint32_t GetTxAvailable (void) const; |
|
72 virtual int Listen(uint32_t queueLimit); |
|
73 |
|
74 virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags); |
|
75 virtual uint32_t GetRxAvailable (void) const; |
|
76 |
|
77 private: |
|
78 friend class Tcp; |
|
79 // invoked by Tcp class |
|
80 int FinishBind (void); |
|
81 void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port); |
|
82 void Destroy (void); |
|
83 int DoSendTo (Ptr<Packet> p, const Address &daddr); |
|
84 int DoSendTo (Ptr<Packet> p, Ipv4Address daddr, uint16_t dport); |
|
85 void SendEmptyPacket(uint8_t flags); |
|
86 //methods for state |
|
87 bool ProcessAction (Actions_t a); |
|
88 bool ProcessAction (Actions_t a, const TcpHeader& tcpHeader, |
|
89 Ipv4Address saddr, Ipv4Address daddr); |
|
90 bool ProcessPacketAction (Actions_t a, Ptr<Packet> p, |
|
91 const TcpHeader& tcpHeader, |
|
92 const Address& fromAddress); |
|
93 Actions_t ProcessEvent (Events_t e); |
|
94 bool SendPendingData(bool withAck = false); |
|
95 void CompleteFork(Ptr<Packet>, const TcpHeader&, const Address& fromAddress); |
|
96 void ConnectionSucceeded(); |
|
97 |
|
98 //methods for window management |
|
99 virtual uint32_t UnAckDataCount(); // Return count of number of unacked bytes |
|
100 virtual uint32_t BytesInFlight(); // Return total bytes in flight |
|
101 virtual uint32_t Window(); // Return window size (integer) |
|
102 virtual uint32_t AvailableWindow();// Return unfilled portion of window |
|
103 |
|
104 // Manage data tx/rx |
|
105 void NewRx (Ptr<Packet>, const TcpHeader&, const Address&); |
|
106 // XXX This should be virtual and overridden |
|
107 Ptr<TcpSocketImpl> Copy (); |
|
108 void NewAck (SequenceNumber seq); |
|
109 // XXX This should be virtual and overridden |
|
110 void DupAck (const TcpHeader& t, uint32_t count); |
|
111 void ReTxTimeout (); |
|
112 void DelAckTimeout (); |
|
113 void LastAckTimeout (); |
|
114 void Retransmit (); |
|
115 void CommonNewAck (SequenceNumber seq, bool skipTimer = false); |
|
116 |
|
117 // attribute related |
|
118 virtual void SetSndBufSize (uint32_t size); |
|
119 virtual uint32_t GetSndBufSize (void) const; |
|
120 virtual void SetRcvBufSize (uint32_t size); |
|
121 virtual uint32_t GetRcvBufSize (void) const; |
|
122 virtual void SetSegSize (uint32_t size); |
|
123 virtual uint32_t GetSegSize (void) const; |
|
124 virtual void SetAdvWin (uint32_t window); |
|
125 virtual uint32_t GetAdvWin (void) const; |
|
126 virtual void SetSSThresh (uint32_t threshold); |
|
127 virtual uint32_t GetSSThresh (void) const; |
|
128 virtual void SetInitialCwnd (uint32_t cwnd); |
|
129 virtual uint32_t GetInitialCwnd (void) const; |
|
130 virtual void SetConnTimeout (Time timeout); |
|
131 virtual Time GetConnTimeout (void) const; |
|
132 virtual void SetConnCount (uint32_t count); |
|
133 virtual uint32_t GetConnCount (void) const; |
|
134 virtual void SetDelAckTimeout (Time timeout); |
|
135 virtual Time GetDelAckTimeout (void) const; |
|
136 virtual void SetDelAckMaxCount (uint32_t count); |
|
137 virtual uint32_t GetDelAckMaxCount (void) const; |
|
138 |
|
139 bool m_skipRetxResched; |
|
140 uint32_t m_dupAckCount; |
|
141 EventId m_retxEvent; |
|
142 EventId m_lastAckEvent; |
|
143 |
|
144 EventId m_delAckEvent; |
|
145 uint32_t m_delAckCount; |
|
146 uint32_t m_delAckMaxCount; |
|
147 Time m_delAckTimeout; |
|
148 |
|
149 Ipv4EndPoint *m_endPoint; |
|
150 Ptr<Node> m_node; |
|
151 Ptr<TcpL4Protocol> m_tcp; |
|
152 Ipv4Address m_remoteAddress; |
|
153 uint16_t m_remotePort; |
|
154 //these two are so that the socket/endpoint cloning works |
|
155 Ipv4Address m_localAddress; |
|
156 uint16_t m_localPort; |
|
157 enum SocketErrno m_errno; |
|
158 bool m_shutdownSend; |
|
159 bool m_shutdownRecv; |
|
160 bool m_connected; |
|
161 |
|
162 //manage the state infomation |
|
163 States_t m_state; |
|
164 bool m_closeNotified; |
|
165 bool m_closeRequestNotified; |
|
166 bool m_closeOnEmpty; |
|
167 bool m_pendingClose; |
|
168 |
|
169 |
|
170 //sequence info, sender side |
|
171 SequenceNumber m_nextTxSequence; |
|
172 SequenceNumber m_highTxMark; |
|
173 SequenceNumber m_highestRxAck; |
|
174 SequenceNumber m_lastRxAck; |
|
175 |
|
176 //sequence info, reciever side |
|
177 SequenceNumber m_nextRxSequence; |
|
178 |
|
179 //history data |
|
180 //this is the incoming data buffer which sorts out of sequence data |
|
181 UnAckData_t m_bufferedData; |
|
182 //this is kind of the tx buffer |
|
183 PendingData* m_pendingData; |
|
184 SequenceNumber m_firstPendingSequence; |
|
185 |
|
186 // Window management |
|
187 uint32_t m_segmentSize; //SegmentSize |
|
188 uint32_t m_rxWindowSize; |
|
189 uint32_t m_advertisedWindowSize; //Window to advertise |
|
190 TracedValue<uint32_t> m_cWnd; //Congestion window |
|
191 uint32_t m_ssThresh; //Slow Start Threshold |
|
192 uint32_t m_initialCWnd; //Initial cWnd value |
|
193 |
|
194 // Round trip time estimation |
|
195 Ptr<RttEstimator> m_rtt; |
|
196 Time m_lastMeasuredRtt; |
|
197 |
|
198 // Timer-related members |
|
199 Time m_cnTimeout; |
|
200 uint32_t m_cnCount; |
|
201 |
|
202 // Temporary queue for delivering data to application |
|
203 uint32_t m_rxAvailable; |
|
204 |
|
205 bool m_wouldBlock; // set to true whenever socket would block on send() |
|
206 |
|
207 // Attributes |
|
208 uint32_t m_sndBufSize; // buffer limit for the outgoing queue |
|
209 uint32_t m_rcvBufSize; // maximum receive socket buffer size |
|
210 }; |
|
211 |
|
212 }//namespace ns3 |
|
213 |
|
214 #endif /* TCP_SOCKET_IMPL_H */ |