LEFT | RIGHT |
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2010 Adrian Sai-wah Tam | 3 * Copyright (c) 2010 Adrian Sai-wah Tam |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "tcp-rx-buffer.h" | 34 #include "tcp-rx-buffer.h" |
35 #include "rtt-estimator.h" | 35 #include "rtt-estimator.h" |
36 | 36 |
37 namespace ns3 { | 37 namespace ns3 { |
38 | 38 |
39 class Ipv4EndPoint; | 39 class Ipv4EndPoint; |
40 class Node; | 40 class Node; |
41 class Packet; | 41 class Packet; |
42 class TcpL4Protocol; | 42 class TcpL4Protocol; |
43 class TcpHeader; | 43 class TcpHeader; |
44 | |
45 /* Names of the 11 TCP states */ | |
46 typedef enum { | |
47 CLOSED, // 0 | |
48 LISTEN, // 1 | |
49 SYN_SENT, // 2 | |
50 SYN_RCVD, // 3 | |
51 ESTABLISHED, // 4 | |
52 CLOSE_WAIT, // 5 | |
53 LAST_ACK, // 6 | |
54 FIN_WAIT_1, // 7 | |
55 FIN_WAIT_2, // 8 | |
56 CLOSING, // 9 | |
57 TIME_WAIT, // 10 | |
58 LAST_STATE } States_t; | |
59 | 44 |
60 /** | 45 /** |
61 * \ingroup socket | 46 * \ingroup socket |
62 * \ingroup tcp | 47 * \ingroup tcp |
63 * | 48 * |
64 * \brief A base class for implementation of a stream socket using TCP. | 49 * \brief A base class for implementation of a stream socket using TCP. |
65 * | 50 * |
66 * This class contains the essential components of TCP, as well as a sockets | 51 * This class contains the essential components of TCP, as well as a sockets |
67 * interface for upper layers to call. This serves as a base for other TCP | 52 * interface for upper layers to call. This serves as a base for other TCP |
68 * functions where the sliding window mechanism is handled here. This class | 53 * functions where the sliding window mechanism is handled here. This class |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 virtual void SetConnTimeout (Time timeout); | 109 virtual void SetConnTimeout (Time timeout); |
125 virtual Time GetConnTimeout (void) const; | 110 virtual Time GetConnTimeout (void) const; |
126 virtual void SetConnCount (uint32_t count); | 111 virtual void SetConnCount (uint32_t count); |
127 virtual uint32_t GetConnCount (void) const; | 112 virtual uint32_t GetConnCount (void) const; |
128 virtual void SetDelAckTimeout (Time timeout); | 113 virtual void SetDelAckTimeout (Time timeout); |
129 virtual Time GetDelAckTimeout (void) const; | 114 virtual Time GetDelAckTimeout (void) const; |
130 virtual void SetDelAckMaxCount (uint32_t count); | 115 virtual void SetDelAckMaxCount (uint32_t count); |
131 virtual uint32_t GetDelAckMaxCount (void) const; | 116 virtual uint32_t GetDelAckMaxCount (void) const; |
132 virtual void SetPersistTimeout (Time timeout); | 117 virtual void SetPersistTimeout (Time timeout); |
133 virtual Time GetPersistTimeout (void) const; | 118 virtual Time GetPersistTimeout (void) const; |
134 virtual void SetAllowBroadcast (bool allowBroadcast); | 119 virtual bool SetAllowBroadcast (bool allowBroadcast); |
135 virtual bool GetAllowBroadcast () const; | 120 virtual bool GetAllowBroadcast () const; |
136 | 121 |
137 // Helper functions: Connection set up | 122 // Helper functions: Connection set up |
138 int SetupCallback (void); // Common part of the two Bind(), i.e. set ca
llback and remembering local addr:port | 123 int SetupCallback (void); // Common part of the two Bind(), i.e. set ca
llback and remembering local addr:port |
139 int DoConnect (void); // Sending a SYN packet to make a connection
if the state allows | 124 int DoConnect (void); // Sending a SYN packet to make a connection
if the state allows |
140 void ConnectionSucceeded (void); // Schedule-friendly wrapper for Socket::Noti
fyConnectionSucceeded() | 125 void ConnectionSucceeded (void); // Schedule-friendly wrapper for Socket::Noti
fyConnectionSucceeded() |
141 int SetupEndpoint (void); // Configure m_endpoint for local addr for gi
ven remote addr | 126 int SetupEndpoint (void); // Configure m_endpoint for local addr for gi
ven remote addr |
142 void CompleteFork (Ptr<Packet>, const TcpHeader&, const Address& fromAddress,
const Address& toAdress); | 127 void CompleteFork (Ptr<Packet>, const TcpHeader&, const Address& fromAddress,
const Address& toAdress); |
143 | 128 |
144 // Helper functions: Transfer operation | 129 // Helper functions: Transfer operation |
145 void ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port, Ptr<Ipv4
Interface> incomingInterface); //Get a pkt from L3 | 130 void ForwardUp (Ptr<Packet> packet, Ipv4Header header, uint16_t port, Ptr<Ipv4
Interface> incomingInterface); //Get a pkt from L3 |
146 bool SendPendingData (bool withAck = false); // Send as much as the window all
ows | 131 bool SendPendingData (bool withAck = false); // Send as much as the window all
ows |
147 void SendEmptyPacket (uint8_t flags); // Send a empty packet that carries a fl
ag, e.g. ACK | 132 void SendEmptyPacket (uint8_t flags); // Send a empty packet that carries a fl
ag, e.g. ACK |
148 void SendRST (void); // Send reset and tear down this socket | 133 void SendRST (void); // Send reset and tear down this socket |
| 134 bool OutOfRange (SequenceNumber32 s) const; // Check if a sequence number is w
ithin rx window |
149 | 135 |
150 // Helper functions: Connection close | 136 // Helper functions: Connection close |
151 int DoClose (void); // Close a socket by sending RST, FIN, or FIN+ACK, depend
on the current state | 137 int DoClose (void); // Close a socket by sending RST, FIN, or FIN+ACK, depend
on the current state |
152 void CloseAndNotify (void); // To CLOSED state, notify upper layer, and deallo
cate end point | 138 void CloseAndNotify (void); // To CLOSED state, notify upper layer, and deallo
cate end point |
153 void Destroy (void); // Kill this socket by zeroing its attributes | 139 void Destroy (void); // Kill this socket by zeroing its attributes |
154 void DeallocateEndPoint (void); // Deallocate m_endPoint | 140 void DeallocateEndPoint (void); // Deallocate m_endPoint |
155 void PeerClose (Ptr<Packet>, const TcpHeader&); // Received a FIN from peer | 141 void PeerClose (Ptr<Packet>, const TcpHeader&); // Received a FIN from peer, n
otify rx buffer |
| 142 void DoPeerClose (void); // FIN is in sequence, notify app and respond with a
FIN |
156 void CancelAllTimers (void); // Cancel all timer when endpoint is deleted | 143 void CancelAllTimers (void); // Cancel all timer when endpoint is deleted |
157 | 144 |
158 // State transition functions | 145 // State transition functions |
159 void ProcessEstablished (Ptr<Packet>, const TcpHeader&); // Received a packet
upon ESTABLISHED state | 146 void ProcessEstablished (Ptr<Packet>, const TcpHeader&); // Received a packet
upon ESTABLISHED state |
160 void ProcessListen (Ptr<Packet>, const TcpHeader&, const Address&, const Addre
ss&); // Process the newly received ACK | 147 void ProcessListen (Ptr<Packet>, const TcpHeader&, const Address&, const Addre
ss&); // Process the newly received ACK |
161 void ProcessSynSent (Ptr<Packet>, const TcpHeader&); // Received a packet upon
SYN_SENT | 148 void ProcessSynSent (Ptr<Packet>, const TcpHeader&); // Received a packet upon
SYN_SENT |
162 void ProcessSynRcvd (Ptr<Packet>, const TcpHeader&, const Address&, const Addr
ess&); // Received a packet upon SYN_RCVD | 149 void ProcessSynRcvd (Ptr<Packet>, const TcpHeader&, const Address&, const Addr
ess&); // Received a packet upon SYN_RCVD |
163 void ProcessWait (Ptr<Packet>, const TcpHeader&); // Received a packet upon CL
OSE_WAIT, FIN_WAIT_1, FIN_WAIT_2 | 150 void ProcessWait (Ptr<Packet>, const TcpHeader&); // Received a packet upon CL
OSE_WAIT, FIN_WAIT_1, FIN_WAIT_2 |
164 void ProcessClosing (Ptr<Packet>, const TcpHeader&); // Received a packet upon
CLOSING | 151 void ProcessClosing (Ptr<Packet>, const TcpHeader&); // Received a packet upon
CLOSING |
165 void ProcessLastAck (Ptr<Packet>, const TcpHeader&); // Received a packet upon
LAST_ACK | 152 void ProcessLastAck (Ptr<Packet>, const TcpHeader&); // Received a packet upon
LAST_ACK |
166 | 153 |
167 // Window management | 154 // Window management |
168 virtual uint32_t UnAckDataCount (void); // Return count of number of una
cked bytes | 155 virtual uint32_t UnAckDataCount (void); // Return count of number of una
cked bytes |
169 virtual uint32_t BytesInFlight (void); // Return total bytes in flight | 156 virtual uint32_t BytesInFlight (void); // Return total bytes in flight |
170 virtual uint32_t Window (void); // Return the max possible numbe
r of unacked bytes | 157 virtual uint32_t Window (void); // Return the max possible numbe
r of unacked bytes |
171 virtual uint32_t AvailableWindow (void); // Return unfilled portion of wi
ndow | 158 virtual uint32_t AvailableWindow (void); // Return unfilled portion of wi
ndow |
172 virtual uint16_t AdvertisedWindowSize (void); // The amount of Rx window annou
nced to the peer | 159 virtual uint16_t AdvertisedWindowSize (void); // The amount of Rx window annou
nced to the peer |
173 | 160 |
174 // Manage data tx/rx | 161 // Manage data tx/rx |
175 virtual Ptr<TcpSocketBase> Fork (void) = 0; // Call CopyObject<> to clone me | 162 virtual Ptr<TcpSocketBase> Fork (void) = 0; // Call CopyObject<> to clone me |
176 virtual void ReceivedAck (Ptr<Packet>, const TcpHeader&); // Received an ACK p
acket | 163 virtual void ReceivedAck (Ptr<Packet>, const TcpHeader&); // Received an ACK p
acket |
177 virtual void ReceivedData (Ptr<Packet>, const TcpHeader&); // Recv of a data,
put into buffer, call L7 to get it if necessary | 164 virtual void ReceivedData (Ptr<Packet>, const TcpHeader&); // Recv of a data,
put into buffer, call L7 to get it if necessary |
| 165 virtual void EstimateRtt (const TcpHeader&); // RTT accounting |
178 virtual void NewAck (SequenceNumber32 const& seq); // Update buffers w.r.t. AC
K | 166 virtual void NewAck (SequenceNumber32 const& seq); // Update buffers w.r.t. AC
K |
179 virtual void DupAck (const TcpHeader& t, uint32_t count) = 0; // Received dupa
ck | 167 virtual void DupAck (const TcpHeader& t, uint32_t count) = 0; // Received dupa
ck |
180 virtual void ReTxTimeout (void); // Call Retransmit() upon RTO event | 168 virtual void ReTxTimeout (void); // Call Retransmit() upon RTO event |
181 virtual void Retransmit (void); // Halving cwnd and call DoRetransmit() | 169 virtual void Retransmit (void); // Halving cwnd and call DoRetransmit() |
182 virtual void DelAckTimeout (void); // Action upon delay ACK timeout, i.e. sen
d an ACK | 170 virtual void DelAckTimeout (void); // Action upon delay ACK timeout, i.e. sen
d an ACK |
183 virtual void LastAckTimeout (void); // Timeout at LAST_ACK, close the connecti
on | 171 virtual void LastAckTimeout (void); // Timeout at LAST_ACK, close the connecti
on |
184 virtual void PersistTimeout (void); // Send 1 byte probe to get an updated win
dow size | 172 virtual void PersistTimeout (void); // Send 1 byte probe to get an updated win
dow size |
185 virtual void DoRetransmit (void); // Retransmit the oldest packet | 173 virtual void DoRetransmit (void); // Retransmit the oldest packet |
186 | 174 |
187 protected: | 175 protected: |
188 // Counters and events | 176 // Counters and events |
189 EventId m_retxEvent; //< Retransmission event | 177 EventId m_retxEvent; //< Retransmission event |
190 EventId m_lastAckEvent; //< Last ACK timeout event | 178 EventId m_lastAckEvent; //< Last ACK timeout event |
191 EventId m_delAckEvent; //< Delayed ACK timeout event | 179 EventId m_delAckEvent; //< Delayed ACK timeout event |
192 EventId m_persistEvent; //< Persist event: Send 1 byte to probe for a non-
zero Rx window | 180 EventId m_persistEvent; //< Persist event: Send 1 byte to probe f
or a non-zero Rx window |
193 uint32_t m_dupAckCount; //< Dupack counter | 181 uint32_t m_dupAckCount; //< Dupack counter |
194 uint32_t m_delAckCount; //< Delayed ACK counter | 182 uint32_t m_delAckCount; //< Delayed ACK counter |
195 uint32_t m_delAckMaxCount; //< Number of packet to fire an ACK before delay t
imeout | 183 uint32_t m_delAckMaxCount; //< Number of packet to fire an ACK befor
e delay timeout |
196 uint32_t m_cnCount; //< Count of remaining connection retries | 184 uint32_t m_cnCount; //< Count of remaining connection retries |
197 Time m_delAckTimeout; //< Time to delay an ACK | 185 TracedValue<Time> m_rto; //< Retransmit timeout |
198 Time m_persistTimeout; //< Time between sending 1-byte probes | 186 TracedValue<Time> m_lastRtt; //< Last RTT sample collected |
199 Time m_cnTimeout; //< Timeout for connection retry | 187 Time m_delAckTimeout; //< Time to delay an ACK |
| 188 Time m_persistTimeout; //< Time between sending 1-byte probes |
| 189 Time m_cnTimeout; //< Timeout for connection retry |
200 | 190 |
201 // Connections to other layers of TCP/IP | 191 // Connections to other layers of TCP/IP |
202 Ipv4EndPoint* m_endPoint; | 192 Ipv4EndPoint* m_endPoint; |
203 Ptr<Node> m_node; | 193 Ptr<Node> m_node; |
204 Ptr<TcpL4Protocol> m_tcp; | 194 Ptr<TcpL4Protocol> m_tcp; |
205 | 195 |
206 // Round trip time estimation | 196 // Round trip time estimation |
207 Ptr<RttEstimator> m_rtt; | 197 Ptr<RttEstimator> m_rtt; |
208 | 198 |
209 // Rx and Tx buffer management | 199 // Rx and Tx buffer management |
210 SequenceNumber32 m_nextTxSequence; //< Next seqnum to be sent (SND.NXT), ReTx
pushes it back | 200 TracedValue<SequenceNumber32> m_nextTxSequence; //< Next seqnum to be sent (SN
D.NXT), ReTx pushes it back |
211 SequenceNumber32 m_highTxMark; //< Highest seqno ever sent, regardless of
ReTx | 201 TracedValue<SequenceNumber32> m_highTxMark; //< Highest seqno ever sent, r
egardless of ReTx |
212 TcpRxBuffer m_rxBuffer; //< Rx buffer (reordering buffer) | 202 TcpRxBuffer m_rxBuffer; //< Rx buffer (reordering buff
er) |
213 TcpTxBuffer m_txBuffer; //< Tx buffer | 203 TcpTxBuffer m_txBuffer; //< Tx buffer |
214 | 204 |
215 // State-related attributes | 205 // State-related attributes |
216 States_t m_state; //< TCP state | 206 TracedValue<TcpStates_t> m_state; //< TCP state |
217 enum SocketErrno m_errno; //< Socket error code | 207 enum SocketErrno m_errno; //< Socket error code |
218 bool m_closeNotified; //< Told app to close socket | 208 bool m_closeNotified; //< Told app to close socket |
219 bool m_closeOnEmpty; //< Close socket upon tx buffer emptied | 209 bool m_closeOnEmpty; //< Close socket upon tx buffer empt
ied |
220 bool m_shutdownSend; //< Send no longer allowed | 210 bool m_shutdownSend; //< Send no longer allowed |
221 bool m_shutdownRecv; //< Receive no longer allowed | 211 bool m_shutdownRecv; //< Receive no longer allowed |
222 bool m_connected; //< Connection established | 212 bool m_connected; //< Connection established |
223 | 213 |
224 // Window management | 214 // Window management |
225 uint32_t m_segmentSize; //< SegmentSize | 215 uint32_t m_segmentSize; //< Segment size |
226 uint32_t m_rxWindowSize; //< Flow control window at remote side | 216 TracedValue<uint32_t> m_rWnd; //< Flow control window at remote side |
227 }; | 217 }; |
228 | 218 |
229 } // namespace ns3 | 219 } // namespace ns3 |
230 | 220 |
231 #endif /* TCP_SOCKET_BASE_H */ | 221 #endif /* TCP_SOCKET_BASE_H */ |
LEFT | RIGHT |