51 * calls to the NSC TCP library. |
51 * calls to the NSC TCP library. |
52 */ |
52 */ |
53 class NscTcpSocketImpl : public TcpSocket |
53 class NscTcpSocketImpl : public TcpSocket |
54 { |
54 { |
55 public: |
55 public: |
|
56 /** |
|
57 * \brief Get the type ID. |
|
58 * \return the object TypeId |
|
59 */ |
56 static TypeId GetTypeId (void); |
60 static TypeId GetTypeId (void); |
57 /** |
61 /** |
58 * Create an unbound tcp socket. |
62 * Create an unbound tcp socket. |
59 */ |
63 */ |
60 NscTcpSocketImpl (); |
64 NscTcpSocketImpl (); |
|
65 |
|
66 /** |
|
67 * Clone a TCP socket, for use upon receiving a connection request in LISTEN state |
|
68 * |
|
69 * \param sock the original Tcp Socket |
|
70 */ |
61 NscTcpSocketImpl (const NscTcpSocketImpl& sock); |
71 NscTcpSocketImpl (const NscTcpSocketImpl& sock); |
62 virtual ~NscTcpSocketImpl (); |
72 virtual ~NscTcpSocketImpl (); |
63 |
73 |
|
74 /** |
|
75 * \brief Set the associated node. |
|
76 * \param node the node |
|
77 */ |
64 void SetNode (Ptr<Node> node); |
78 void SetNode (Ptr<Node> node); |
|
79 |
|
80 /** |
|
81 * \brief Set the associated TCP L4 protocol. |
|
82 * \param tcp the TCP L4 protocol |
|
83 */ |
65 void SetTcp (Ptr<NscTcpL4Protocol> tcp); |
84 void SetTcp (Ptr<NscTcpL4Protocol> tcp); |
66 |
85 |
67 virtual enum SocketErrno GetErrno (void) const; |
86 virtual enum SocketErrno GetErrno (void) const; |
68 virtual enum SocketType GetSocketType (void) const; |
87 virtual enum SocketType GetSocketType (void) const; |
69 virtual Ptr<Node> GetNode (void) const; |
88 virtual Ptr<Node> GetNode (void) const; |
85 virtual int GetSockName (Address &address) const; |
104 virtual int GetSockName (Address &address) const; |
86 virtual bool SetAllowBroadcast (bool allowBroadcast); |
105 virtual bool SetAllowBroadcast (bool allowBroadcast); |
87 virtual bool GetAllowBroadcast () const; |
106 virtual bool GetAllowBroadcast () const; |
88 |
107 |
89 private: |
108 private: |
|
109 /** |
|
110 * \brief Called by NscTcpSocketImpl::ForwardUp() |
|
111 * |
|
112 * Actually performs the ForwardUp operations |
|
113 */ |
90 void NSCWakeup (void); |
114 void NSCWakeup (void); |
91 friend class Tcp; |
115 friend class Tcp; |
92 // invoked by Tcp class |
116 // invoked by Tcp class |
|
117 /** |
|
118 * Finish the binding process |
|
119 * \returns 0 on success, -1 on failure |
|
120 */ |
93 int FinishBind (void); |
121 int FinishBind (void); |
|
122 /** |
|
123 * \brief Called by the L3 protocol when it received a packet to pass on to TCP. |
|
124 * |
|
125 * \param p the incoming packet |
|
126 * \param header the packet's IPv4 header |
|
127 * \param port the incoming port |
|
128 * \param incomingInterface the incoming interface |
|
129 */ |
94 void ForwardUp (Ptr<Packet> p, Ipv4Header header, uint16_t port, |
130 void ForwardUp (Ptr<Packet> p, Ipv4Header header, uint16_t port, |
95 Ptr<Ipv4Interface> incomingInterface); |
131 Ptr<Ipv4Interface> incomingInterface); |
|
132 /** |
|
133 * \brief Kill this socket by zeroing its attributes (IPv4) |
|
134 * |
|
135 * This is a callback function configured to m_endpoint in |
|
136 * SetupCallback(), invoked when the endpoint is destroyed. |
|
137 */ |
96 void Destroy (void); |
138 void Destroy (void); |
97 //methods for state |
139 //methods for state |
|
140 /** |
|
141 * \brief Send all the pending data |
|
142 * \returns true on success |
|
143 */ |
98 bool SendPendingData (void); |
144 bool SendPendingData (void); |
|
145 /** |
|
146 * \brief Read all the pending data |
|
147 * \returns true on success |
|
148 */ |
99 bool ReadPendingData (void); |
149 bool ReadPendingData (void); |
|
150 /** |
|
151 * \brief Accept an incoming connection |
|
152 * \returns true on success |
|
153 */ |
100 bool Accept (void); |
154 bool Accept (void); |
|
155 /** |
|
156 * \brief Complete the Fork operations (after a connection has been accepted) |
|
157 */ |
101 void CompleteFork (void); |
158 void CompleteFork (void); |
|
159 |
|
160 /** |
|
161 * \brief Called when a connection is in Established state |
|
162 */ |
102 void ConnectionSucceeded (); |
163 void ConnectionSucceeded (); |
103 |
164 |
104 // Manage data tx/rx |
165 // Manage data tx/rx |
105 /// \todo This should be virtual and overridden |
166 // \todo This should be virtual and overridden |
|
167 /** |
|
168 * \brief Copy self |
|
169 * \returns a copy of self |
|
170 */ |
106 Ptr<NscTcpSocketImpl> Copy (); |
171 Ptr<NscTcpSocketImpl> Copy (); |
107 |
172 |
108 // attribute related |
173 // attribute related |
109 virtual void SetSndBufSize (uint32_t size); |
174 virtual void SetSndBufSize (uint32_t size); |
110 virtual uint32_t GetSndBufSize (void) const; |
175 virtual uint32_t GetSndBufSize (void) const; |
111 virtual void SetRcvBufSize (uint32_t size); |
176 virtual void SetRcvBufSize (uint32_t size); |
112 virtual uint32_t GetRcvBufSize (void) const; |
177 virtual uint32_t GetRcvBufSize (void) const; |
113 virtual void SetSegSize (uint32_t size); |
178 virtual void SetSegSize (uint32_t size); |
114 virtual uint32_t GetSegSize (void) const; |
179 virtual uint32_t GetSegSize (void) const; |
|
180 /** |
|
181 * \brief Set the Advertised Window size |
|
182 * \param window the window size |
|
183 */ |
115 virtual void SetAdvWin (uint32_t window); |
184 virtual void SetAdvWin (uint32_t window); |
|
185 /** |
|
186 * \brief Get the Advertised Window size |
|
187 * \returns the window size |
|
188 */ |
116 virtual uint32_t GetAdvWin (void) const; |
189 virtual uint32_t GetAdvWin (void) const; |
117 virtual void SetSSThresh (uint32_t threshold); |
190 virtual void SetSSThresh (uint32_t threshold); |
118 virtual uint32_t GetSSThresh (void) const; |
191 virtual uint32_t GetSSThresh (void) const; |
119 virtual void SetInitialCwnd (uint32_t cwnd); |
192 virtual void SetInitialCwnd (uint32_t cwnd); |
120 virtual uint32_t GetInitialCwnd (void) const; |
193 virtual uint32_t GetInitialCwnd (void) const; |
129 virtual void SetTcpNoDelay (bool noDelay); |
202 virtual void SetTcpNoDelay (bool noDelay); |
130 virtual bool GetTcpNoDelay (void) const; |
203 virtual bool GetTcpNoDelay (void) const; |
131 virtual void SetPersistTimeout (Time timeout); |
204 virtual void SetPersistTimeout (Time timeout); |
132 virtual Time GetPersistTimeout (void) const; |
205 virtual Time GetPersistTimeout (void) const; |
133 |
206 |
|
207 /** |
|
208 * \brief Translate between a NSC error and a ns-3 error code |
|
209 * \param err NSC error |
|
210 * \returns ns-3 error code |
|
211 */ |
134 enum Socket::SocketErrno GetNativeNs3Errno (int err) const; |
212 enum Socket::SocketErrno GetNativeNs3Errno (int err) const; |
135 uint32_t m_delAckMaxCount; |
213 uint32_t m_delAckMaxCount; //!< Number of packet to fire an ACK before delay timeout |
136 Time m_delAckTimeout; |
214 Time m_delAckTimeout; //!< Time to delay an ACK |
137 bool m_noDelay; |
215 bool m_noDelay; //!< Disable ACk delay |
138 |
216 |
139 Ipv4EndPoint *m_endPoint; |
217 Ipv4EndPoint *m_endPoint; //!< the IPv4 endpoint |
140 Ptr<Node> m_node; |
218 Ptr<Node> m_node; //!< the associated node |
141 Ptr<NscTcpL4Protocol> m_tcp; |
219 Ptr<NscTcpL4Protocol> m_tcp; //!< the associated TCP L4 protocol |
142 Ipv4Address m_remoteAddress; |
220 Ipv4Address m_remoteAddress; //!< peer IP address |
143 uint16_t m_remotePort; |
221 uint16_t m_remotePort; //!< peer port |
144 //these two are so that the socket/endpoint cloning works |
222 //these two are so that the socket/endpoint cloning works |
145 Ipv4Address m_localAddress; |
223 Ipv4Address m_localAddress; //!< local address |
146 uint16_t m_localPort; |
224 uint16_t m_localPort; //!< local port |
147 InetSocketAddress m_peerAddress; |
225 InetSocketAddress m_peerAddress; //!< peer IP and port |
148 enum SocketErrno m_errno; |
226 enum SocketErrno m_errno; //!< last error number |
149 bool m_shutdownSend; |
227 bool m_shutdownSend; //!< Send no longer allowed |
150 bool m_shutdownRecv; |
228 bool m_shutdownRecv; //!< Receive no longer allowed |
151 bool m_connected; |
229 bool m_connected; //!< Connection established |
152 |
230 |
153 //manage the state information |
231 //manage the state information |
154 TracedValue<TcpStates_t> m_state; |
232 TracedValue<TcpStates_t> m_state; //!< state information |
155 bool m_closeOnEmpty; |
233 bool m_closeOnEmpty; //!< true if socket will close when buffer is empty |
156 |
234 |
157 //needed to queue data when in SYN_SENT state |
235 //needed to queue data when in SYN_SENT state |
158 std::queue<Ptr<Packet> > m_txBuffer; |
236 std::queue<Ptr<Packet> > m_txBuffer; //!< transmission buffer |
159 uint32_t m_txBufferSize; |
237 uint32_t m_txBufferSize; //!< transmission buffer size |
160 |
238 |
161 // Window management |
239 // Window management |
162 uint32_t m_segmentSize; //SegmentSize |
240 uint32_t m_segmentSize; //!< SegmentSize |
163 uint32_t m_rxWindowSize; |
241 uint32_t m_rxWindowSize; //!< Receive window size |
164 uint32_t m_advertisedWindowSize; //Window to advertise |
242 uint32_t m_advertisedWindowSize; //!< Window to advertise |
165 TracedValue<uint32_t> m_cWnd; //Congestion window |
243 TracedValue<uint32_t> m_cWnd; //!< Congestion window |
166 uint32_t m_ssThresh; //Slow Start Threshold |
244 uint32_t m_ssThresh; //!< Slow Start Threshold |
167 uint32_t m_initialCWnd; //Initial cWnd value |
245 uint32_t m_initialCWnd; //!< Initial cWnd value |
168 |
246 |
169 // Round trip time estimation |
247 // Round trip time estimation |
170 Time m_lastMeasuredRtt; |
248 Time m_lastMeasuredRtt; //!< Last measured RTT |
171 |
249 |
172 // Timer-related members |
250 // Timer-related members |
173 Time m_cnTimeout; |
251 Time m_cnTimeout; //!< Timeout for connection retry |
174 uint32_t m_cnCount; |
252 uint32_t m_cnCount; //!< Count of remaining connection retries |
175 Time m_persistTimeout; |
253 Time m_persistTimeout; //!< Time between sending 1-byte probes |
176 |
254 |
177 // Temporary queue for delivering data to application |
255 // Temporary queue for delivering data to application |
178 std::queue<Ptr<Packet> > m_deliveryQueue; |
256 std::queue<Ptr<Packet> > m_deliveryQueue; //!< receive buffer |
179 uint32_t m_rxAvailable; |
257 uint32_t m_rxAvailable; //!< receive buffer available size |
180 INetStreamSocket* m_nscTcpSocket; |
258 INetStreamSocket* m_nscTcpSocket; //!< the real NSC TCP socket |
181 |
259 |
182 // Attributes |
260 // Attributes |
183 uint32_t m_sndBufSize; // buffer limit for the outgoing queue |
261 uint32_t m_sndBufSize; //!< buffer limit for the outgoing queue |
184 uint32_t m_rcvBufSize; // maximum receive socket buffer size |
262 uint32_t m_rcvBufSize; //!< maximum receive socket buffer size |
185 }; |
263 }; |
186 |
264 |
187 } // namespace ns3 |
265 } // namespace ns3 |
188 |
266 |
189 #endif /* NSC_TCP_SOCKET_IMPL_H */ |
267 #endif /* NSC_TCP_SOCKET_IMPL_H */ |