00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * This program is free software; you can redistribute it and/or modify 00004 * it under the terms of the GNU General Public License version 2 as 00005 * published by the Free Software Foundation; 00006 * 00007 * This program is distributed in the hope that it will be useful, 00008 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00009 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00010 * GNU General Public License for more details. 00011 * 00012 * You should have received a copy of the GNU General Public License 00013 * along with this program; if not, write to the Free Software 00014 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00015 */ 00016 #ifndef NSC_TCP_SOCKET_IMPL_H 00017 #define NSC_TCP_SOCKET_IMPL_H 00018 00019 #include <stdint.h> 00020 #include <queue> 00021 #include <vector> 00022 00023 #include "ns3/callback.h" 00024 #include "ns3/traced-value.h" 00025 #include "ns3/tcp-socket.h" 00026 #include "ns3/ptr.h" 00027 #include "ns3/ipv4-address.h" 00028 #include "ns3/inet-socket-address.h" 00029 #include "ns3/event-id.h" 00030 #include "tcp-typedefs.h" 00031 #include "pending-data.h" 00032 #include "sequence-number.h" 00033 #include "rtt-estimator.h" 00034 00035 namespace ns3 { 00036 00037 class Ipv4EndPoint; 00038 class Node; 00039 class Packet; 00040 class NscTcpL4Protocol; 00041 class TcpHeader; 00042 00043 /** 00044 * \ingroup socket 00045 * \ingroup nsctcp 00046 * 00047 * \brief Socket logic for the NSC TCP sockets. 00048 * 00049 * Most of the TCP internal 00050 * logic is handled by the NSC tcp library itself; this class maps ns3::Socket 00051 * calls to the NSC TCP library. 00052 */ 00053 class NscTcpSocketImpl : public TcpSocket 00054 { 00055 public: 00056 static TypeId GetTypeId (void); 00057 /** 00058 * Create an unbound tcp socket. 00059 */ 00060 NscTcpSocketImpl (); 00061 NscTcpSocketImpl (const NscTcpSocketImpl& sock); 00062 virtual ~NscTcpSocketImpl (); 00063 00064 void SetNode (Ptr<Node> node); 00065 void SetTcp (Ptr<NscTcpL4Protocol> tcp); 00066 void SetRtt (Ptr<RttEstimator> rtt); 00067 00068 virtual enum SocketErrno GetErrno (void) const; 00069 virtual Ptr<Node> GetNode (void) const; 00070 virtual int Bind (void); 00071 virtual int Bind (const Address &address); 00072 virtual int Close (void); 00073 virtual int ShutdownSend (void); 00074 virtual int ShutdownRecv (void); 00075 virtual int Connect(const Address &address); 00076 virtual int Listen(void); 00077 virtual uint32_t GetTxAvailable (void) const; 00078 virtual int Send (Ptr<Packet> p, uint32_t flags); 00079 virtual int SendTo(Ptr<Packet> p, uint32_t flags, const Address &toAddress); 00080 virtual uint32_t GetRxAvailable (void) const; 00081 virtual Ptr<Packet> Recv (uint32_t maxSize, uint32_t flags); 00082 virtual Ptr<Packet> RecvFrom (uint32_t maxSize, uint32_t flags, 00083 Address &fromAddress); 00084 virtual int GetSockName (Address &address) const; 00085 00086 private: 00087 void NSCWakeup(void); 00088 friend class Tcp; 00089 // invoked by Tcp class 00090 int FinishBind (void); 00091 void ForwardUp (Ptr<Packet> p, Ipv4Address ipv4, uint16_t port); 00092 void Destroy (void); 00093 //methods for state 00094 bool SendPendingData(void); 00095 bool ReadPendingData(void); 00096 bool Accept(void); 00097 void CompleteFork(void); 00098 void ConnectionSucceeded(); 00099 00100 // Manage data tx/rx 00101 // XXX This should be virtual and overridden 00102 Ptr<NscTcpSocketImpl> Copy (); 00103 00104 // attribute related 00105 virtual void SetSndBufSize (uint32_t size); 00106 virtual uint32_t GetSndBufSize (void) const; 00107 virtual void SetRcvBufSize (uint32_t size); 00108 virtual uint32_t GetRcvBufSize (void) const; 00109 virtual void SetSegSize (uint32_t size); 00110 virtual uint32_t GetSegSize (void) const; 00111 virtual void SetAdvWin (uint32_t window); 00112 virtual uint32_t GetAdvWin (void) const; 00113 virtual void SetSSThresh (uint32_t threshold); 00114 virtual uint32_t GetSSThresh (void) const; 00115 virtual void SetInitialCwnd (uint32_t cwnd); 00116 virtual uint32_t GetInitialCwnd (void) const; 00117 virtual void SetConnTimeout (Time timeout); 00118 virtual Time GetConnTimeout (void) const; 00119 virtual void SetConnCount (uint32_t count); 00120 virtual uint32_t GetConnCount (void) const; 00121 virtual void SetDelAckTimeout (Time timeout); 00122 virtual Time GetDelAckTimeout (void) const; 00123 virtual void SetDelAckMaxCount (uint32_t count); 00124 virtual uint32_t GetDelAckMaxCount (void) const; 00125 00126 enum Socket::SocketErrno GetNativeNs3Errno(int err) const; 00127 uint32_t m_delAckMaxCount; 00128 Time m_delAckTimeout; 00129 00130 Ipv4EndPoint *m_endPoint; 00131 Ptr<Node> m_node; 00132 Ptr<NscTcpL4Protocol> m_tcp; 00133 Ipv4Address m_remoteAddress; 00134 uint16_t m_remotePort; 00135 //these two are so that the socket/endpoint cloning works 00136 Ipv4Address m_localAddress; 00137 uint16_t m_localPort; 00138 InetSocketAddress m_peerAddress; 00139 enum SocketErrno m_errno; 00140 bool m_shutdownSend; 00141 bool m_shutdownRecv; 00142 bool m_connected; 00143 00144 //manage the state infomation 00145 States_t m_state; 00146 bool m_closeOnEmpty; 00147 00148 //needed to queue data when in SYN_SENT state 00149 std::queue<Ptr<Packet> > m_txBuffer; 00150 uint32_t m_txBufferSize; 00151 00152 // Window management 00153 uint32_t m_segmentSize; //SegmentSize 00154 uint32_t m_rxWindowSize; 00155 uint32_t m_advertisedWindowSize; //Window to advertise 00156 TracedValue<uint32_t> m_cWnd; //Congestion window 00157 uint32_t m_ssThresh; //Slow Start Threshold 00158 uint32_t m_initialCWnd; //Initial cWnd value 00159 00160 // Round trip time estimation 00161 Ptr<RttEstimator> m_rtt; 00162 Time m_lastMeasuredRtt; 00163 00164 // Timer-related members 00165 Time m_cnTimeout; 00166 uint32_t m_cnCount; 00167 00168 // Temporary queue for delivering data to application 00169 std::queue<Ptr<Packet> > m_deliveryQueue; 00170 uint32_t m_rxAvailable; 00171 INetStreamSocket* m_nscTcpSocket; 00172 00173 // Attributes 00174 uint32_t m_sndBufSize; // buffer limit for the outgoing queue 00175 uint32_t m_rcvBufSize; // maximum receive socket buffer size 00176 }; 00177 00178 }//namespace ns3 00179 00180 #endif /* NSC_TCP_SOCKET_IMPL_H */