|
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 "tcp-typedefs.h" |
|
31 #include "pending-data.h" |
|
32 #include "sequence-number.h" |
|
33 #include "rtt-estimator.h" |
|
34 |
|
35 #include "nsc/sim/sim_interface.h" |
|
36 |
|
37 namespace ns3 { |
|
38 |
|
39 class Ipv4EndPoint; |
|
40 class Node; |
|
41 class Packet; |
|
42 class NscTcpL4Protocol; |
|
43 class TcpHeader; |
|
44 |
|
45 class NscTcpSocketImpl : public TcpSocket |
|
46 { |
|
47 public: |
|
48 static TypeId GetTypeId (void); |
|
49 /** |
|
50 * Create an unbound tcp socket. |
|
51 */ |
|
52 NscTcpSocketImpl (); |
|
53 NscTcpSocketImpl (const NscTcpSocketImpl& sock); |
|
54 virtual ~NscTcpSocketImpl (); |
|
55 |
|
56 void SetNode (Ptr<Node> node); |
|
57 void SetTcp (Ptr<NscTcpL4Protocol> 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 Listen(uint32_t queueLimit); |
|
69 virtual uint32_t GetTxAvailable (void) const; |
|
70 virtual int Send (Ptr<Packet> p, uint32_t flags); |
|
71 virtual int SendTo(Ptr<Packet> p, uint32_t flags, const Address &toAddress); |
|
72 virtual uint32_t GetRxAvailable (void) const; |
|
73 virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags); |
|
74 virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags, |
|
75 Address &fromAddress); |
|
76 |
|
77 private: |
|
78 void NSCWakeup(void); |
|
79 friend class Tcp; |
|
80 // invoked by Tcp class |
|
81 int FinishBind (void); |
|
82 void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port); |
|
83 void Destroy (void); |
|
84 //methods for state |
|
85 bool SendPendingData(void); |
|
86 bool ReadPendingData(void); |
|
87 bool Accept(void); |
|
88 void CompleteFork(void); |
|
89 void ConnectionSucceeded(); |
|
90 |
|
91 // Manage data tx/rx |
|
92 // XXX This should be virtual and overridden |
|
93 Ptr<NscTcpSocketImpl> Copy (); |
|
94 |
|
95 // attribute related |
|
96 virtual void SetSndBufSize (uint32_t size); |
|
97 virtual uint32_t GetSndBufSize (void) const; |
|
98 virtual void SetRcvBufSize (uint32_t size); |
|
99 virtual uint32_t GetRcvBufSize (void) const; |
|
100 virtual void SetSegSize (uint32_t size); |
|
101 virtual uint32_t GetSegSize (void) const; |
|
102 virtual void SetAdvWin (uint32_t window); |
|
103 virtual uint32_t GetAdvWin (void) const; |
|
104 virtual void SetSSThresh (uint32_t threshold); |
|
105 virtual uint32_t GetSSThresh (void) const; |
|
106 virtual void SetInitialCwnd (uint32_t cwnd); |
|
107 virtual uint32_t GetInitialCwnd (void) const; |
|
108 virtual void SetConnTimeout (Time timeout); |
|
109 virtual Time GetConnTimeout (void) const; |
|
110 virtual void SetConnCount (uint32_t count); |
|
111 virtual uint32_t GetConnCount (void) const; |
|
112 virtual void SetDelAckTimeout (Time timeout); |
|
113 virtual Time GetDelAckTimeout (void) const; |
|
114 virtual void SetDelAckMaxCount (uint32_t count); |
|
115 virtual uint32_t GetDelAckMaxCount (void) const; |
|
116 |
|
117 enum Socket::SocketErrno GetNativeNs3Errno(int err) const; |
|
118 uint32_t m_delAckMaxCount; |
|
119 Time m_delAckTimeout; |
|
120 |
|
121 Ipv4EndPoint *m_endPoint; |
|
122 Ptr<Node> m_node; |
|
123 Ptr<NscTcpL4Protocol> m_tcp; |
|
124 Ipv4Address m_remoteAddress; |
|
125 uint16_t m_remotePort; |
|
126 //these two are so that the socket/endpoint cloning works |
|
127 Ipv4Address m_localAddress; |
|
128 uint16_t m_localPort; |
|
129 InetSocketAddress m_peerAddress; |
|
130 enum SocketErrno m_errno; |
|
131 bool m_shutdownSend; |
|
132 bool m_shutdownRecv; |
|
133 bool m_connected; |
|
134 |
|
135 //manage the state infomation |
|
136 States_t m_state; |
|
137 bool m_closeOnEmpty; |
|
138 |
|
139 //needed to queue data when in SYN_SENT state |
|
140 std::queue<Ptr<Packet> > m_txBuffer; |
|
141 uint32_t m_txBufferSize; |
|
142 |
|
143 // Window management |
|
144 uint32_t m_segmentSize; //SegmentSize |
|
145 uint32_t m_rxWindowSize; |
|
146 uint32_t m_advertisedWindowSize; //Window to advertise |
|
147 TracedValue<uint32_t> m_cWnd; //Congestion window |
|
148 uint32_t m_ssThresh; //Slow Start Threshold |
|
149 uint32_t m_initialCWnd; //Initial cWnd value |
|
150 |
|
151 // Round trip time estimation |
|
152 Ptr<RttEstimator> m_rtt; |
|
153 Time m_lastMeasuredRtt; |
|
154 |
|
155 // Timer-related members |
|
156 Time m_cnTimeout; |
|
157 uint32_t m_cnCount; |
|
158 |
|
159 // Temporary queue for delivering data to application |
|
160 std::queue<Ptr<Packet> > m_deliveryQueue; |
|
161 uint32_t m_rxAvailable; |
|
162 INetStreamSocket* m_nscTcpSocket; |
|
163 |
|
164 // Attributes |
|
165 uint32_t m_sndBufSize; // buffer limit for the outgoing queue |
|
166 uint32_t m_rcvBufSize; // maximum receive socket buffer size |
|
167 }; |
|
168 |
|
169 }//namespace ns3 |
|
170 |
|
171 #endif /* NSC_TCP_SOCKET_IMPL_H */ |