diff --git a/src/internet-node/rtt-estimator.cc b/src/internet-node/rtt-estimator.cc index 8a6d07a20..0e7801ac5 100644 --- a/src/internet-node/rtt-estimator.cc +++ b/src/internet-node/rtt-estimator.cc @@ -29,7 +29,7 @@ #include "rtt-estimator.h" #include "ns3/simulator.h" -#include "ns3/type-id-default-value.h" +#include "ns3/double.h" namespace ns3{ @@ -40,19 +40,21 @@ TypeId RttEstimator::GetTypeId (void) { static TypeId tid = TypeId ("RttEstimator") - .SetParent (); + .SetParent () + .AddAttribute ("MaxMultiplier", + "XXX", + Double (64.0), + MakeDoubleAccessor (&RttEstimator::m_maxMultiplier), + MakeDoubleChecker ()) + .AddAttribute ("InitialEstimation", + "XXX", + Seconds (1.0), + MakeTimeAccessor (&RttEstimator::est), + MakeTimeChecker ()) + ; return tid; } -//Default values -TypeIdDefaultValue RttEstimator::defaultTid ("RttEstimator", - "Tahoe round trip time estimation", - RttEstimator::GetTypeId (), "RttMeanDeviation"); -NumericDefaultValue RttEstimator::defaultMaxMultiplier ("RttMaxMultiplier","",64.0); - -// RttEstimator Static Member variables -Time RttEstimator::initialEstimate = Seconds (1.0); // Default initial estimate - //RttHistory methods RttHistory::RttHistory (SequenceNumber s, uint32_t c, Time t) : seq (s), count (c), time (t), retx (false) @@ -66,7 +68,7 @@ RttHistory::RttHistory (const RttHistory& h) // Base class methods -RttEstimator::RttEstimator () : next (1), history (), est (initialEstimate), +RttEstimator::RttEstimator () : next (1), history (), nSamples (0), multiplier (1.0) { //note next=1 everywhere since first segment will have sequence 1 @@ -142,7 +144,7 @@ void RttEstimator::ClearSent () void RttEstimator::IncreaseMultiplier () { - multiplier = std::min (multiplier * 2.0, defaultMaxMultiplier.GetValue ()); + multiplier = std::min (multiplier * 2.0, m_maxMultiplier); } void RttEstimator::ResetMultiplier () @@ -153,24 +155,13 @@ void RttEstimator::ResetMultiplier () void RttEstimator::Reset () { // Reset to initial state next = 1; - est = initialEstimate; + est = Seconds (1.0); // XXX: we should go back to the 'initial value' here. Need to add support in Object for this. history.clear (); // Remove all info from the history nSamples = 0; ResetMultiplier (); } -// Base class, static methods -void RttEstimator::InitialEstimate (Time e) -{ // Set a new default initial estimate - initialEstimate = e; -} -Ptr RttEstimator::CreateDefault () -{ - TypeId tid = defaultTid.GetValue (); - Ptr rtte = tid.CreateObject (0.1, initialEstimate)->GetObject (); - return rtte; -} //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -183,13 +174,18 @@ RttMeanDeviation::GetTypeId (void) { static TypeId tid = TypeId ("RttMeanDeviation") .SetParent () - .AddConstructor () - .AddConstructor (); + .AddConstructor () + .AddAttribute ("Gain", + "XXX", + Double (0.1), + MakeDoubleAccessor (&RttMeanDeviation::gain), + MakeDoubleChecker ()) + ; return tid; } -RttMeanDeviation::RttMeanDeviation(double g) : - gain (g), variance (ns3::Seconds(0)) +RttMeanDeviation::RttMeanDeviation() : + variance (ns3::Seconds(0)) { } @@ -198,11 +194,6 @@ RttMeanDeviation::RttMeanDeviation (const RttMeanDeviation& c) { } -RttMeanDeviation::RttMeanDeviation (double g, Time e) : - RttEstimator (e), gain (g), variance (ns3::Seconds(0)) -{ -} - void RttMeanDeviation::Measurement (Time m) { if (nSamples) diff --git a/src/internet-node/rtt-estimator.h b/src/internet-node/rtt-estimator.h index 3161f8b8b..695727648 100644 --- a/src/internet-node/rtt-estimator.h +++ b/src/internet-node/rtt-estimator.h @@ -71,19 +71,12 @@ public: private: SequenceNumber next; // Next expected sequence to be sent RttHistory_t history; // List of sent packet + double m_maxMultiplier; + Time m_initialEstimate; public: Time est; // Current estimate uint32_t nSamples;// Number of samples double multiplier; // RTO Multiplier -public: - static void InitialEstimate(Time); - static Ptr CreateDefault(); // Retrieve current default - - static TypeIdDefaultValue defaultTid; - static NumericDefaultValue defaultMaxMultiplier; - -private: - static Time initialEstimate; // Default initial estimate }; // The "Mean-Deviation" estimator, as discussed by Van Jacobson @@ -96,16 +89,8 @@ class RttMeanDeviation : public RttEstimator { public : static TypeId GetTypeId (void); - //Doc:Desc Constructor for {\tt RttMeanDeviation} specifying the gain factor for the - //Doc:Desc estimator. - //Doc:Arg1 Gain factor. - RttMeanDeviation (double g); + RttMeanDeviation (); - //Doc:Desc Constructor for {\tt RttMeanDeviation} specifying the gain factor - //Doc:Desc and the initial estimate. - //Doc:Arg1 Gain factor. - //Doc:Arg2 Initial estimate. - RttMeanDeviation (double g, Time e); //Doc:Method RttMeanDeviation (const RttMeanDeviation&); // Copy constructor diff --git a/src/internet-node/tcp-header.cc b/src/internet-node/tcp-header.cc index 15905d71e..ff06b06e6 100644 --- a/src/internet-node/tcp-header.cc +++ b/src/internet-node/tcp-header.cc @@ -44,11 +44,10 @@ TcpHeader::TcpHeader () m_ackNumber (0), m_length (5), m_flags (0), - m_windowSize (Tcp::defaultAdvWin.GetValue ()), + m_windowSize (0), m_checksum (0), m_urgentPointer (0) -{ -} +{} TcpHeader::~TcpHeader () {} diff --git a/src/internet-node/tcp-l4-protocol.cc b/src/internet-node/tcp-l4-protocol.cc index 0f1ebddff..1a0464503 100644 --- a/src/internet-node/tcp-l4-protocol.cc +++ b/src/internet-node/tcp-l4-protocol.cc @@ -311,6 +311,14 @@ static TcpStateMachine tcpStateMachine; //only instance of a TcpStateMachine /* see http://www.iana.org/assignments/protocol-numbers */ const uint8_t TcpL4Protocol::PROT_NUMBER = 6; +ObjectFactory +TcpL4Protocol::GetDefaultRttEstimatorFactory (void) +{ + ObjectFactory factory; + factory.SetTypeId ("RttMeanDeviation"); + return factory; +} + TypeId TcpL4Protocol::GetTypeId (void) { @@ -321,6 +329,11 @@ TcpL4Protocol::GetTypeId (void) Ptr (0), MakePtrAccessor (&TcpL4Protocol::m_node), MakePtrChecker ()) + .AddAttribute ("RttEstimatorFactory", + "How RttEstimator objects are created.", + GetDefaultRttEstimatorFactory (), + MakeObjectFactoryAccessor (&TcpL4Protocol::m_rttFactory), + MakeObjectFactoryChecker ()) ; return tid; } @@ -365,7 +378,8 @@ Ptr TcpL4Protocol::CreateSocket (void) { NS_LOG_FUNCTION; - Ptr socket = Create (m_node, this); + Ptr rtt = m_rttFactory.Create (); + Ptr socket = CreateObject (m_node, this, rtt); return socket; } diff --git a/src/internet-node/tcp-l4-protocol.h b/src/internet-node/tcp-l4-protocol.h index 73bfb8e97..583d325f1 100644 --- a/src/internet-node/tcp-l4-protocol.h +++ b/src/internet-node/tcp-l4-protocol.h @@ -26,6 +26,7 @@ #include "ns3/packet.h" #include "ns3/ipv4-address.h" #include "ns3/ptr.h" +#include "ns3/object-factory.h" #include "ipv4-end-point-demux.h" #include "ipv4-l4-protocol.h" #include "ipv4-interface.h" @@ -103,10 +104,12 @@ protected: private: Ptr m_node; Ipv4EndPointDemux *m_endPoints; + ObjectFactory m_rttFactory; private: friend class TcpSocket; void SendPacket (Ptr, TcpHeader, Ipv4Address, Ipv4Address); + static ObjectFactory GetDefaultRttEstimatorFactory (void); }; }; // namespace ns3 diff --git a/src/internet-node/tcp-socket.cc b/src/internet-node/tcp-socket.cc index f2d8ad4cd..dcac0ef18 100644 --- a/src/internet-node/tcp-socket.cc +++ b/src/internet-node/tcp-socket.cc @@ -31,7 +31,6 @@ #include "tcp-typedefs.h" #include "ns3/simulator.h" #include "ns3/packet.h" -#include "ns3/default-value.h" #include @@ -41,7 +40,7 @@ using namespace std; namespace ns3 { -TcpSocket::TcpSocket (Ptr node, Ptr tcp) + TcpSocket::TcpSocket (Ptr node, Ptr tcp, Ptr rtt) : m_skipRetxResched (false), m_dupAckCount (0), m_endPoint (0), @@ -62,19 +61,22 @@ TcpSocket::TcpSocket (Ptr node, Ptr tcp) m_lastRxAck (0), m_nextRxSequence (0), m_pendingData (0), - m_segmentSize (Tcp::defaultSegSize.GetValue()), - m_rxWindowSize (Tcp::defaultAdvWin.GetValue()), - m_advertisedWindowSize (Tcp::defaultAdvWin.GetValue()), - m_cWnd (Tcp::defaultInitialCWnd.GetValue() * m_segmentSize), - m_ssThresh (Tcp::defaultSSThresh.GetValue()), - m_initialCWnd (Tcp::defaultInitialCWnd.GetValue()), - m_rtt (RttEstimator::CreateDefault()), - m_lastMeasuredRtt (Seconds(0.0)), - m_cnTimeout (Seconds (Tcp::defaultConnTimeout.GetValue ())), - m_cnCount (Tcp::defaultConnCount.GetValue ()) + m_rtt (rtt), + m_lastMeasuredRtt (Seconds(0.0)) { NS_LOG_FUNCTION; NS_LOG_PARAMS (this< 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 (); + } TcpSocket::~TcpSocket () diff --git a/src/internet-node/tcp-socket.h b/src/internet-node/tcp-socket.h index 3a7970fe8..4f9f0fde9 100644 --- a/src/internet-node/tcp-socket.h +++ b/src/internet-node/tcp-socket.h @@ -45,7 +45,7 @@ public: /** * Create an unbound tcp socket. */ - TcpSocket (Ptr node, Ptr tcp); + TcpSocket (Ptr node, Ptr tcp, Ptr rtt); virtual ~TcpSocket (); virtual enum SocketErrno GetErrno (void) const; diff --git a/src/node/tcp.cc b/src/node/tcp.cc index 55a0927a3..6bc15e884 100644 --- a/src/node/tcp.cc +++ b/src/node/tcp.cc @@ -18,58 +18,100 @@ * Author: Raj Bhattacharjea */ #include "tcp.h" +#include "ns3/uinteger.h" namespace ns3 { -NumericDefaultValue Tcp::defaultSegSize -("TcpDefaultSegmentSize", -"Default TCP maximum segment size in bytes (may be adjusted based on MTU discovery)", -536); - -NumericDefaultValue Tcp::defaultAdvWin -("TcpDefaultAdvertisedWindowSize", -"Default TCP advertised window size (bytes)", -0xffff); - -NumericDefaultValue Tcp::defaultSSThresh -("TcpDefaultSlowStartThreshold", -"Default TCP slow start threshold (bytes)", -0xffff); - -NumericDefaultValue Tcp::defaultTxBuffer -("TcpDefaultTxBufferSize", -"Default TCP maximum transmit buffer size (bytes)", -0xffffffffl); - -NumericDefaultValue Tcp::defaultRxBuffer -("TcpDefaultRxBufferSize", -"Default TCP maximum receive buffer size (bytes)", -0xffffffffl); - -NumericDefaultValue Tcp::defaultInitialCWnd -("TcpDefaultInitialCongestionWindowSize", -"Default TCP initial congestion window size (segments)", -1); - -NumericDefaultValue Tcp::defaultConnTimeout -("TcpDefaultConnTimeout", -"Default TCP retransmission timeout when opening connection (seconds)", -3); - -NumericDefaultValue Tcp::defaultConnCount -("TcpDefaultConnCount", -"Default number of connection attempts (SYN retransmissions) before returning failure", -6); - NS_OBJECT_ENSURE_REGISTERED (Tcp); TypeId Tcp::GetTypeId (void) { static TypeId tid = TypeId ("Tcp") - .SetParent (); + .SetParent () + .AddAttribute ("TcpDefaultSegmentSize", + "Default TCP maximum segment size in bytes (may be adjusted based on MTU discovery)", + Uinteger (536), + MakeUintegerAccessor (&Tcp::m_defaultSegSize), + MakeUintegerChecker ()) + .AddAttribute ("TcpDefaultAdvertisedWindowSize", + "Default TCP advertised window size (bytes)", + Uinteger (0xffff), + MakeUintegerAccessor (&Tcp::m_defaultAdvWin), + MakeUintegerChecker ()) + .AddAttribute ("TcpDefaultSlowStartThreshold", + "Default TCP slow start threshold (bytes)", + Uinteger (0xffff), + MakeUintegerAccessor (&Tcp::m_defaultSsThresh), + MakeUintegerChecker ()) + .AddAttribute ("TcpDefaultTxBufferSize", + "Default TCP maximum transmit buffer size (bytes)", + Uinteger (0xffffffffl), + MakeUintegerAccessor (&Tcp::m_defaultTxBuffer), + MakeUintegerChecker ()) + .AddAttribute ("TcpDefaultRxBufferSize", + "Default TCP maximum receive buffer size (bytes)", + Uinteger (0xffffffffl), + MakeUintegerAccessor (&Tcp::m_defaultRxBuffer), + MakeUintegerChecker ()) + .AddAttribute ("TcpDefaultInitialCongestionWindowSize", + "Default TCP initial congestion window size (segments)", + Uinteger (1), + MakeUintegerAccessor (&Tcp::m_defaultInitialCwnd), + MakeUintegerChecker ()) + .AddAttribute ("TcpDefaultConnTimeout", + "Default TCP retransmission timeout when opening connection (seconds)", + Uinteger (3), + MakeUintegerAccessor (&Tcp::m_defaultConnTimeout), + MakeUintegerChecker ()) + .AddAttribute ("TcpDefaultConnCount", + "Default number of connection attempts (SYN retransmissions) before returning failure", + Uinteger (6), + MakeUintegerAccessor (&Tcp::m_defaultConnCount), + MakeUintegerChecker ()) + ; return tid; } +uint32_t +Tcp::GetDefaultSegSize (void) const +{ + return m_defaultSegSize; +} +uint32_t +Tcp::GetDefaultAdvWin (void) const +{ + return m_defaultAdvWin; +} +uint32_t +Tcp::GetDefaultSsThresh (void) const +{ + return m_defaultSsThresh; +} +uint32_t +Tcp::GetDefaultTxBuffer (void) const +{ + return m_defaultTxBuffer; +} +uint32_t +Tcp::GetDefaultRxBuffer (void) const +{ + return m_defaultRxBuffer; +} +uint32_t +Tcp::GetDefaultInitialCwnd (void) const +{ + return m_defaultInitialCwnd; +} +uint32_t +Tcp::GetDefaultConnTimeout (void) const +{ + return m_defaultConnTimeout; +} +uint32_t +Tcp::GetDefaultConnCount (void) const +{ + return m_defaultConnCount; +} } // namespace ns3 diff --git a/src/node/tcp.h b/src/node/tcp.h index 189b7fc61..ffb9e22d1 100644 --- a/src/node/tcp.h +++ b/src/node/tcp.h @@ -20,7 +20,6 @@ #ifndef TCP_H #define TCP_H -#include "ns3/default-value.h" #include "socket-factory.h" namespace ns3 { @@ -48,18 +47,26 @@ public: virtual Ptr CreateSocket (void) = 0; -public: - static NumericDefaultValue defaultSegSize; - static NumericDefaultValue defaultAdvWin; - static NumericDefaultValue defaultSSThresh; - static NumericDefaultValue defaultTxBuffer; - static NumericDefaultValue defaultRxBuffer; - static NumericDefaultValue defaultInitialCWnd; - static NumericDefaultValue defaultConnTimeout; - static NumericDefaultValue defaultConnCount; + 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; +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; }; } // namespace ns3 -#endif /* UDP_H */ +#endif /* TCP_H */