/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef NSC_TCP_SOCKET_IMPL_H #define NSC_TCP_SOCKET_IMPL_H #include #include #include #include "ns3/callback.h" #include "ns3/traced-value.h" #include "ns3/tcp-socket.h" #include "ns3/ptr.h" #include "ns3/ipv4-address.h" #include "ns3/inet-socket-address.h" #include "ns3/event-id.h" #include "tcp-typedefs.h" #include "pending-data.h" #include "ns3/sequence-number.h" struct INetStreamSocket; namespace ns3 { class Ipv4EndPoint; class Node; class Packet; class NscTcpL4Protocol; class TcpHeader; /** * \ingroup socket * \ingroup nsctcp * * \brief Socket logic for the NSC TCP sockets. * * Most of the TCP internal * logic is handled by the NSC tcp library itself; this class maps ns3::Socket * calls to the NSC TCP library. */ class NscTcpSocketImpl : public TcpSocket { public: static TypeId GetTypeId (void); /** * Create an unbound tcp socket. */ NscTcpSocketImpl (); NscTcpSocketImpl (const NscTcpSocketImpl& sock); virtual ~NscTcpSocketImpl (); void SetNode (Ptr node); void SetTcp (Ptr tcp); virtual enum SocketErrno GetErrno (void) const; virtual Ptr GetNode (void) const; virtual int Bind (void); virtual int Bind (const Address &address); virtual int Close (void); virtual int ShutdownSend (void); virtual int ShutdownRecv (void); virtual int Connect(const Address &address); virtual int Listen(void); virtual uint32_t GetTxAvailable (void) const; virtual int Send (Ptr p, uint32_t flags); virtual int SendTo(Ptr p, uint32_t flags, const Address &toAddress); virtual uint32_t GetRxAvailable (void) const; virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual Ptr RecvFrom (uint32_t maxSize, uint32_t flags, Address &fromAddress); virtual int GetSockName (Address &address) const; private: void NSCWakeup(void); friend class Tcp; // invoked by Tcp class int FinishBind (void); void ForwardUp (Ptr p, Ipv4Address saddr, Ipv4Address daddr, uint16_t port); void Destroy (void); //methods for state bool SendPendingData(void); bool ReadPendingData(void); bool Accept(void); void CompleteFork(void); void ConnectionSucceeded(); // Manage data tx/rx // XXX This should be virtual and overridden Ptr Copy (); // attribute related virtual void SetSndBufSize (uint32_t size); virtual uint32_t GetSndBufSize (void) const; virtual void SetRcvBufSize (uint32_t size); virtual uint32_t GetRcvBufSize (void) const; virtual void SetSegSize (uint32_t size); virtual uint32_t GetSegSize (void) const; virtual void SetAdvWin (uint32_t window); virtual uint32_t GetAdvWin (void) const; virtual void SetSSThresh (uint32_t threshold); virtual uint32_t GetSSThresh (void) const; virtual void SetInitialCwnd (uint32_t cwnd); virtual uint32_t GetInitialCwnd (void) const; virtual void SetConnTimeout (Time timeout); virtual Time GetConnTimeout (void) const; virtual void SetConnCount (uint32_t count); virtual uint32_t GetConnCount (void) const; virtual void SetDelAckTimeout (Time timeout); virtual Time GetDelAckTimeout (void) const; virtual void SetDelAckMaxCount (uint32_t count); virtual uint32_t GetDelAckMaxCount (void) const; enum Socket::SocketErrno GetNativeNs3Errno(int err) const; uint32_t m_delAckMaxCount; Time m_delAckTimeout; Ipv4EndPoint *m_endPoint; Ptr m_node; Ptr m_tcp; Ipv4Address m_remoteAddress; uint16_t m_remotePort; //these two are so that the socket/endpoint cloning works Ipv4Address m_localAddress; uint16_t m_localPort; InetSocketAddress m_peerAddress; enum SocketErrno m_errno; bool m_shutdownSend; bool m_shutdownRecv; bool m_connected; //manage the state information States_t m_state; bool m_closeOnEmpty; //needed to queue data when in SYN_SENT state std::queue > m_txBuffer; uint32_t m_txBufferSize; // Window management uint32_t m_segmentSize; //SegmentSize uint32_t m_rxWindowSize; uint32_t m_advertisedWindowSize; //Window to advertise TracedValue m_cWnd; //Congestion window uint32_t m_ssThresh; //Slow Start Threshold uint32_t m_initialCWnd; //Initial cWnd value // Round trip time estimation Time m_lastMeasuredRtt; // Timer-related members Time m_cnTimeout; uint32_t m_cnCount; // Temporary queue for delivering data to application std::queue > m_deliveryQueue; uint32_t m_rxAvailable; INetStreamSocket* m_nscTcpSocket; // Attributes uint32_t m_sndBufSize; // buffer limit for the outgoing queue uint32_t m_rcvBufSize; // maximum receive socket buffer size }; }//namespace ns3 #endif /* NSC_TCP_SOCKET_IMPL_H */