diff --git a/src/internet-node/tcp-socket-impl.cc b/src/internet-node/tcp-socket-impl.cc index 26ad2dc0a..57c0e0d09 100644 --- a/src/internet-node/tcp-socket-impl.cc +++ b/src/internet-node/tcp-socket-impl.cc @@ -48,7 +48,7 @@ TypeId TcpSocketImpl::GetTypeId () { static TypeId tid = TypeId("ns3::TcpSocketImpl") - .SetParent () + .SetParent () .AddTraceSource ("CongestionWindow", "The TCP connection's congestion window", MakeTraceSourceAccessor (&TcpSocketImpl::m_cWnd)) @@ -81,12 +81,9 @@ TcpSocketImpl::GetTypeId () m_rtt (0), m_lastMeasuredRtt (Seconds(0.0)), m_rxAvailable (0), - m_sndBufLimit (0xffffffff), - m_rcvBufLimit (0xffffffff), m_wouldBlock (false) { NS_LOG_FUNCTION (this); - } TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) @@ -95,7 +92,7 @@ TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) m_dupAckCount (sock.m_dupAckCount), m_delAckCount (0), m_delAckMaxCount (sock.m_delAckMaxCount), - m_delAckTimout (sock.m_delAckTimout), + m_delAckTimeout (sock.m_delAckTimeout), m_endPoint (0), m_node (sock.m_node), m_tcp (sock.m_tcp), @@ -128,9 +125,7 @@ TcpSocketImpl::TcpSocketImpl(const TcpSocketImpl& sock) m_lastMeasuredRtt (Seconds(0.0)), m_cnTimeout (sock.m_cnTimeout), m_cnCount (sock.m_cnCount), - m_rxAvailable (0), - m_sndBufLimit (0xffffffff), - m_rcvBufLimit (0xffffffff) + m_rxAvailable (0) { NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC("Invoked the copy constructor"); @@ -176,17 +171,9 @@ void TcpSocketImpl::SetNode (Ptr node) { m_node = node; - Ptr t = node->GetObject (); - m_segmentSize = t->GetDefaultSegSize (); - m_rxWindowSize = t->GetDefaultAdvWin (); - m_advertisedWindowSize = t->GetDefaultAdvWin (); - m_cWnd = t->GetDefaultInitialCwnd () * m_segmentSize; - m_ssThresh = t->GetDefaultSsThresh (); - m_initialCWnd = t->GetDefaultInitialCwnd (); - m_cnTimeout = Seconds (t->GetDefaultConnTimeout ()); - m_cnCount = t->GetDefaultConnCount (); - m_delAckTimout = Seconds(t->GetDefaultDelAckTimeout ()); - m_delAckMaxCount = t->GetDefaultDelAckCount (); + // Initialize some variables + m_cWnd = m_initialCWnd * m_segmentSize; + m_rxWindowSize = m_advertisedWindowSize; } void @@ -452,12 +439,12 @@ TcpSocketImpl::GetTxAvailable (void) const { uint32_t unAckedDataSize = m_pendingData->SizeFromSeq (m_firstPendingSequence, m_highestRxAck); - NS_ASSERT (m_sndBufLimit >= unAckedDataSize); //else a logical error - return m_sndBufLimit-unAckedDataSize; + NS_ASSERT (m_sndBufSize >= unAckedDataSize); //else a logical error + return m_sndBufSize-unAckedDataSize; } else { - return m_sndBufLimit; + return m_sndBufSize; } } @@ -500,34 +487,6 @@ TcpSocketImpl::GetRxAvailable (void) const return m_rxAvailable; } -void -TcpSocketImpl::SetSndBuf (uint32_t size) -{ - NS_LOG_FUNCTION_NOARGS (); - m_sndBufLimit = size; -} - -uint32_t -TcpSocketImpl::GetSndBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_sndBufLimit; -} - -void -TcpSocketImpl::SetRcvBuf (uint32_t size) -{ - NS_LOG_FUNCTION_NOARGS (); - m_rcvBufLimit = size; -} - -uint32_t -TcpSocketImpl::GetRcvBuf (void) const -{ - NS_LOG_FUNCTION_NOARGS (); - return m_rcvBufLimit; -} - void TcpSocketImpl::ForwardUp (Ptr packet, Ipv4Address ipv4, uint16_t port) { @@ -1153,7 +1112,7 @@ void TcpSocketImpl::NewRx (Ptr p, } else { - m_delAckEvent = Simulator::Schedule (m_delAckTimout, &TcpSocketImpl::DelAckTimeout, this); + m_delAckEvent = Simulator::Schedule (m_delAckTimeout, &TcpSocketImpl::DelAckTimeout, this); } } @@ -1351,4 +1310,124 @@ void TcpSocketImpl::Retransmit () m_remoteAddress); } +void +TcpSocketImpl::SetSndBufSize (uint32_t size) +{ + m_sndBufSize = size; +} + +uint32_t +TcpSocketImpl::GetSndBufSize (void) const +{ + return m_sndBufSize; +} + +void +TcpSocketImpl::SetRcvBufSize (uint32_t size) +{ + m_rcvBufSize = size; +} + +uint32_t +TcpSocketImpl::GetRcvBufSize (void) const +{ + return m_rcvBufSize; +} + +void +TcpSocketImpl::SetSegSize (uint32_t size) +{ + m_segmentSize = size; +} + +uint32_t +TcpSocketImpl::GetSegSize (void) const +{ + return m_segmentSize; +} + +void +TcpSocketImpl::SetAdvWin (uint32_t window) +{ + m_advertisedWindowSize = window; +} + +uint32_t +TcpSocketImpl::GetAdvWin (void) const +{ + return m_advertisedWindowSize; +} + +void +TcpSocketImpl::SetSSThresh (uint32_t threshold) +{ + m_ssThresh = threshold; +} + +uint32_t +TcpSocketImpl::GetSSThresh (void) const +{ + return m_ssThresh; +} + +void +TcpSocketImpl::SetInitialCwnd (uint32_t cwnd) +{ + m_initialCWnd = cwnd; +} + +uint32_t +TcpSocketImpl::GetInitialCwnd (void) const +{ + return m_initialCWnd; +} + +void +TcpSocketImpl::SetConnTimeout (Time timeout) +{ + m_cnTimeout = timeout; +} + +Time +TcpSocketImpl::GetConnTimeout (void) const +{ + return m_cnTimeout; +} + +void +TcpSocketImpl::SetConnCount (uint32_t count) +{ + m_cnCount = count; +} + +uint32_t +TcpSocketImpl::GetConnCount (void) const +{ + return m_cnCount; +} + +void +TcpSocketImpl::SetDelAckTimeout (Time timeout) +{ + m_delAckTimeout = timeout; +} + +Time +TcpSocketImpl::GetDelAckTimeout (void) const +{ + return m_delAckTimeout; +} + +void +TcpSocketImpl::SetDelAckMaxCount (uint32_t count) +{ + m_delAckMaxCount = count; +} + +uint32_t +TcpSocketImpl::GetDelAckMaxCount (void) const +{ + return m_delAckMaxCount; +} + }//namespace ns3 diff --git a/src/internet-node/tcp-socket-impl.h b/src/internet-node/tcp-socket-impl.h index 0171f2e6d..7adc8669e 100644 --- a/src/internet-node/tcp-socket-impl.h +++ b/src/internet-node/tcp-socket-impl.h @@ -74,12 +74,6 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; -protected: - virtual void SetSndBuf (uint32_t size); - virtual uint32_t GetSndBuf (void) const; - virtual void SetRcvBuf (uint32_t size); - virtual uint32_t GetRcvBuf (void) const; - private: friend class Tcp; // invoked by Tcp class @@ -120,6 +114,28 @@ private: void Retransmit (); void CommonNewAck (SequenceNumber seq, bool skipTimer = false); + // 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; + bool m_skipRetxResched; uint32_t m_dupAckCount; EventId m_retxEvent; @@ -128,7 +144,7 @@ private: EventId m_delAckEvent; uint32_t m_delAckCount; uint32_t m_delAckMaxCount; - Time m_delAckTimout; + Time m_delAckTimeout; Ipv4EndPoint *m_endPoint; Ptr m_node; @@ -187,9 +203,11 @@ private: std::queue > m_deliveryQueue; uint32_t m_rxAvailable; - uint32_t m_sndBufLimit; // buffer limit for the outgoing queue - uint32_t m_rcvBufLimit; // maximum receive socket buffer size bool m_wouldBlock; // set to true whenever socket would block on send() + + // Attributes + uint32_t m_rcvBufSize; // maximum receive socket buffer size + uint32_t m_sndBufSize; // buffer limit for the outgoing queue }; }//namespace ns3 diff --git a/src/internet-node/udp-socket-impl.h b/src/internet-node/udp-socket-impl.h index 71bded586..42047a5d0 100644 --- a/src/internet-node/udp-socket-impl.h +++ b/src/internet-node/udp-socket-impl.h @@ -64,6 +64,7 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags); virtual uint32_t GetRxAvailable (void) const; +private: // Attributes set through UdpSocket base class virtual void SetRcvBufSize (uint32_t size); virtual uint32_t GetRcvBufSize (void) const; @@ -72,7 +73,6 @@ public: virtual void SetIpMulticastTtl (uint32_t ipTtl); virtual uint32_t GetIpMulticastTtl (void) const; -private: friend class UdpSocketFactory; // invoked by Udp class int FinishBind (void); diff --git a/src/node/tcp-socket-factory.cc b/src/node/tcp-socket-factory.cc index 40d1caa66..ca1ae25b8 100644 --- a/src/node/tcp-socket-factory.cc +++ b/src/node/tcp-socket-factory.cc @@ -30,111 +30,8 @@ TcpSocketFactory::GetTypeId (void) { static TypeId tid = TypeId ("ns3::TcpSocketFactory") .SetParent () - .AddAttribute ("DefaultSegmentSize", - "Default TCP maximum segment size in bytes (may be adjusted based on MTU discovery)", - UintegerValue (536), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultSegSize), - MakeUintegerChecker ()) - .AddAttribute ("DefaultAdvertisedWindowSize", - "Default TCP advertised window size (bytes)", - UintegerValue (0xffff), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultAdvWin), - MakeUintegerChecker ()) - .AddAttribute ("DefaultSlowStartThreshold", - "Default TCP slow start threshold (bytes)", - UintegerValue (0xffff), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultSsThresh), - MakeUintegerChecker ()) - .AddAttribute ("DefaultTxBufferSize", - "Default TCP maximum transmit buffer size (bytes)", - UintegerValue (0xffffffffl), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultTxBuffer), - MakeUintegerChecker ()) - .AddAttribute ("DefaultRxBufferSize", - "Default TCP maximum receive buffer size (bytes)", - UintegerValue (0xffffffffl), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultRxBuffer), - MakeUintegerChecker ()) - .AddAttribute ("DefaultInitialCongestionWindowSize", - "Default TCP initial congestion window size (segments)", - UintegerValue (1), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultInitialCwnd), - MakeUintegerChecker ()) - .AddAttribute ("DefaultConnTimeout", - "Default TCP retransmission timeout when opening connection (seconds)", - UintegerValue (3), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultConnTimeout), - MakeUintegerChecker ()) - .AddAttribute ("DefaultConnCount", - "Default number of connection attempts (SYN retransmissions) before returning failure", - UintegerValue (6), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultConnCount), - MakeUintegerChecker ()) - .AddAttribute ("DefaultDelAckTimeout", - "Default timeout value for TCP delayed acks, in seconds", - DoubleValue (0.2), - MakeDoubleAccessor (&TcpSocketFactory::m_defaultDelAckTimeout), - MakeDoubleChecker ()) - .AddAttribute ("DefaultDelAckCount", - "Default number of packets to wait before sending a TCP ack", - UintegerValue (2), - MakeUintegerAccessor (&TcpSocketFactory::m_defaultDelAckCount), - MakeUintegerChecker ()) - ; + ; return tid; } -uint32_t -TcpSocketFactory::GetDefaultSegSize (void) const -{ - return m_defaultSegSize; -} -uint32_t -TcpSocketFactory::GetDefaultAdvWin (void) const -{ - return m_defaultAdvWin; -} -uint32_t -TcpSocketFactory::GetDefaultSsThresh (void) const -{ - return m_defaultSsThresh; -} -uint32_t -TcpSocketFactory::GetDefaultTxBuffer (void) const -{ - return m_defaultTxBuffer; -} -uint32_t -TcpSocketFactory::GetDefaultRxBuffer (void) const -{ - return m_defaultRxBuffer; -} -uint32_t -TcpSocketFactory::GetDefaultInitialCwnd (void) const -{ - return m_defaultInitialCwnd; -} -uint32_t -TcpSocketFactory::GetDefaultConnTimeout (void) const -{ - return m_defaultConnTimeout; -} -uint32_t -TcpSocketFactory::GetDefaultConnCount (void) const -{ - return m_defaultConnCount; -} - -double -TcpSocketFactory::GetDefaultDelAckTimeout (void) const -{ - return m_defaultDelAckTimeout; -} - -uint32_t -TcpSocketFactory::GetDefaultDelAckCount (void) const -{ - return m_defaultDelAckCount; -} - } // namespace ns3 diff --git a/src/node/tcp-socket-factory.h b/src/node/tcp-socket-factory.h index 9d98eafff..35909cb54 100644 --- a/src/node/tcp-socket-factory.h +++ b/src/node/tcp-socket-factory.h @@ -48,29 +48,6 @@ public: virtual Ptr CreateSocket (void) = 0; - uint32_t GetDefaultSegSize (void) const; - uint32_t GetDefaultAdvWin (void) const; - uint32_t GetDefaultSsThresh (void) const; - uint32_t GetDefaultTxBuffer (void) const; - uint32_t GetDefaultRxBuffer (void) const; - uint32_t GetDefaultInitialCwnd (void) const; - uint32_t GetDefaultConnTimeout (void) const; - uint32_t GetDefaultConnCount (void) const; - double GetDefaultDelAckTimeout (void) const; - uint32_t GetDefaultDelAckCount (void) const; - -private: - uint32_t m_defaultSegSize; - uint32_t m_defaultAdvWin; - uint32_t m_defaultSsThresh; - uint32_t m_defaultTxBuffer; - uint32_t m_defaultRxBuffer; - uint32_t m_defaultInitialCwnd; - uint32_t m_defaultConnTimeout; - uint32_t m_defaultConnCount; - double m_defaultDelAckTimeout; - uint32_t m_defaultDelAckCount; - }; } // namespace ns3 diff --git a/src/node/tcp-socket.cc b/src/node/tcp-socket.cc index 3d3a83d67..1dd3d4057 100644 --- a/src/node/tcp-socket.cc +++ b/src/node/tcp-socket.cc @@ -21,7 +21,9 @@ #include "ns3/object.h" #include "ns3/log.h" #include "ns3/uinteger.h" +#include "ns3/double.h" #include "ns3/trace-source-accessor.h" +#include "ns3/nstime.h" #include "tcp-socket.h" NS_LOG_COMPONENT_DEFINE ("TcpSocket"); @@ -35,26 +37,66 @@ TcpSocket::GetTypeId (void) { static TypeId tid = TypeId ("ns3::TcpSocket") .SetParent () -#if 0 + .AddAttribute ("SndBufSize", + "TcpSocket maximum transmit buffer size (bytes)", + UintegerValue (0xffffffffl), + MakeUintegerAccessor (&TcpSocket::GetSndBufSize, + &TcpSocket::SetSndBufSize), + MakeUintegerChecker ()) .AddAttribute ("RcvBufSize", "TcpSocket maximum receive buffer size (bytes)", UintegerValue (0xffffffffl), MakeUintegerAccessor (&TcpSocket::GetRcvBufSize, &TcpSocket::SetRcvBufSize), MakeUintegerChecker ()) - .AddAttribute ("IpTtl", - "socket-specific TTL for unicast IP packets (if non-zero)", - UintegerValue (0), - MakeUintegerAccessor (&TcpSocket::GetIpTtl, - &TcpSocket::SetIpTtl), + .AddAttribute ("SegmentSize", + "TCP maximum segment size in bytes (may be adjusted based on MTU discovery)", + UintegerValue (536), + MakeUintegerAccessor (&TcpSocket::GetSegSize, + &TcpSocket::SetSegSize), MakeUintegerChecker ()) - .AddAttribute ("IpMulticastTtl", - "socket-specific TTL for multicast IP packets (if non-zero)", - UintegerValue (0), - MakeUintegerAccessor (&TcpSocket::GetIpMulticastTtl, - &TcpSocket::SetIpMulticastTtl), + .AddAttribute ("AdvertisedWindowSize", + "TCP advertised window size (bytes)", + UintegerValue (0xffff), + MakeUintegerAccessor (&TcpSocket::GetAdvWin, + &TcpSocket::SetAdvWin), + MakeUintegerChecker ()) + .AddAttribute ("SlowStartThreshold", + "TCP slow start threshold (bytes)", + UintegerValue (0xffff), + MakeUintegerAccessor (&TcpSocket::GetSSThresh, + &TcpSocket::SetSSThresh), + MakeUintegerChecker ()) + .AddAttribute ("InitialCwnd", + "TCP initial congestion window size (segments)", + UintegerValue (1), + MakeUintegerAccessor (&TcpSocket::GetInitialCwnd, + &TcpSocket::SetInitialCwnd), + MakeUintegerChecker ()) + .AddAttribute ("ConnTimeout", + "TCP retransmission timeout when opening connection (seconds)", + TimeValue (Seconds (3)), + MakeTimeAccessor (&TcpSocket::GetConnTimeout, + &TcpSocket::SetConnTimeout), + MakeTimeChecker ()) + .AddAttribute ("ConnCount", + "Number of connection attempts (SYN retransmissions) before returning failure", + UintegerValue (6), + MakeUintegerAccessor (&TcpSocket::GetConnCount, + &TcpSocket::SetConnCount), + MakeUintegerChecker ()) + .AddAttribute ("DelAckTimeout", + "Timeout value for TCP delayed acks, in seconds", + TimeValue (Seconds (0.2)), + MakeTimeAccessor (&TcpSocket::GetDelAckTimeout, + &TcpSocket::SetDelAckTimeout), + MakeTimeChecker ()) + .AddAttribute ("DelAckCount", + "Number of packets to wait before sending a TCP ack", + UintegerValue (2), + MakeUintegerAccessor (&TcpSocket::GetDelAckMaxCount, + &TcpSocket::SetDelAckMaxCount), MakeUintegerChecker ()) -#endif ; return tid; } diff --git a/src/node/tcp-socket.h b/src/node/tcp-socket.h index bc48ebf93..9092474f4 100644 --- a/src/node/tcp-socket.h +++ b/src/node/tcp-socket.h @@ -28,6 +28,7 @@ #include "ns3/callback.h" #include "ns3/ptr.h" #include "ns3/object.h" +#include "ns3/nstime.h" namespace ns3 { @@ -61,16 +62,28 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags) = 0; virtual uint32_t GetRxAvailable (void) const = 0; -public: -#if 0 +private: // Indirect the attribute setting and getting through private virtual methods + virtual void SetSndBufSize (uint32_t size) = 0; + virtual uint32_t GetSndBufSize (void) const = 0; virtual void SetRcvBufSize (uint32_t size) = 0; virtual uint32_t GetRcvBufSize (void) const = 0; - virtual void SetIpTtl (uint32_t ipTtl) = 0; - virtual uint32_t GetIpTtl (void) const = 0; - virtual void SetIpMulticastTtl (uint32_t ipTtl) = 0; - virtual uint32_t GetIpMulticastTtl (void) const = 0; -#endif + virtual void SetSegSize (uint32_t size) = 0; + virtual uint32_t GetSegSize (void) const = 0; + virtual void SetAdvWin (uint32_t window) = 0; + virtual uint32_t GetAdvWin (void) const = 0; + virtual void SetSSThresh (uint32_t threshold) = 0; + virtual uint32_t GetSSThresh (void) const = 0; + virtual void SetInitialCwnd (uint32_t count) = 0; + virtual uint32_t GetInitialCwnd (void) const = 0; + virtual void SetConnTimeout (Time timeout) = 0; + virtual Time GetConnTimeout (void) const = 0; + virtual void SetConnCount (uint32_t count) = 0; + virtual uint32_t GetConnCount (void) const = 0; + virtual void SetDelAckTimeout (Time timeout) = 0; + virtual Time GetDelAckTimeout (void) const = 0; + virtual void SetDelAckMaxCount (uint32_t count) = 0; + virtual uint32_t GetDelAckMaxCount (void) const = 0; }; diff --git a/src/node/udp-socket.h b/src/node/udp-socket.h index 5f20fd7c0..1c81916c2 100644 --- a/src/node/udp-socket.h +++ b/src/node/udp-socket.h @@ -61,7 +61,7 @@ public: virtual Ptr Recv (uint32_t maxSize, uint32_t flags) = 0; virtual uint32_t GetRxAvailable (void) const = 0; -public: +private: // Indirect the attribute setting and getting through private virtual methods virtual void SetRcvBufSize (uint32_t size) = 0; virtual uint32_t GetRcvBufSize (void) const = 0;