24 #include "ns3/random-variable-stream.h"
43 static TypeId GetTypeId (
void);
72 void SetInvalidAwndCb (InvalidAwndCallback cb);
83 virtual uint16_t AdvertisedWindowSize (
bool scale =
true)
const;
86 uint16_t OldAdvertisedWindowSize (
bool scale =
true)
const;
102 m_inwalidAwndCb = cb;
108 static TypeId tid =
TypeId (
"ns3::TcpSocketAdvertisedWindowProxy")
110 .SetGroupName (
"Internet")
119 return CopyObject<TcpSocketAdvertisedWindowProxy> (
this);
128 uint16_t oldAwnd = OldAdvertisedWindowSize (scale);
130 if (!m_rxBuffer->Finished ())
134 if (newAwnd != oldAwnd)
136 uint32_t available = m_rxBuffer->Available ();
141 uint32_t newAwndKnownDifference = newAwnd;
144 newAwndKnownDifference += (available >> m_rcvWindShift);
148 newAwndKnownDifference += available;
151 if (newAwndKnownDifference > m_maxWinSize)
153 newAwndKnownDifference = m_maxWinSize;
156 if (static_cast<uint16_t> (newAwndKnownDifference) != oldAwnd)
158 if (!m_inwalidAwndCb.IsNull ())
160 m_inwalidAwndCb(oldAwnd, newAwnd);
188 uint32_t
w = m_rxBuffer->MaxBufferSize ();
192 w >>= m_rcvWindShift;
194 if (w > m_maxWinSize)
197 NS_LOG_WARN (
"Adv window size truncated to " << m_maxWinSize <<
"; possibly to avoid overflow of the 16-bit integer");
199 NS_LOG_DEBUG (
"Returning AdvertisedWindowSize of " << static_cast<uint16_t> (w));
200 return static_cast<uint16_t
> (
w);
218 static TypeId GetTypeId (
void);
226 m_prng = CreateObject<UniformRandomVariable> ();
234 virtual void DoReset (
void) { };
244 static TypeId tid =
TypeId (
"ns3::TcpDropRatioErrorModel")
254 return m_prng->GetValue () < m_dropRatio;
293 virtual void ConfigureEnvironment ();
302 void InvalidAwndCb (uint16_t oldAwnd, uint16_t newAwnd);
309 uint32_t size, uint32_t packets,
double lossRatio)
312 m_pktCount (packets),
313 m_lossRatio (lossRatio)
320 TcpGeneralTest::ConfigureEnvironment ();
334 DynamicCast<TcpSocketAdvertisedWindowProxy> (sock)->SetExpectedSegmentSize (500);
335 DynamicCast<TcpSocketAdvertisedWindowProxy> (sock)->SetInvalidAwndCb (
344 return CreateObject<TcpDropRatioErrorModel> (
m_lossRatio);
351 "Old and new AWND calculations do not match.");
366 std::vector<uint32_t> &toDrop);
386 uint32_t size, uint32_t packets,
387 std::vector<uint32_t> &toDrop)
390 m_pktCount (packets),
398 TcpGeneralTest::ConfigureEnvironment ();
411 DynamicCast<TcpSocketAdvertisedWindowProxy> (sock)->SetExpectedSegmentSize (500);
412 DynamicCast<TcpSocketAdvertisedWindowProxy> (sock)->SetInvalidAwndCb (
421 auto socket = TcpGeneralTest::CreateSenderSocket (node);
431 for (std::vector<uint32_t>::iterator it =
m_toDrop.begin (); it !=
m_toDrop.end (); ++it)
443 "Old and new AWND calculations do not match.");
472 std::vector<uint32_t> toDrop;
473 toDrop.push_back(8001);
474 toDrop.push_back(9001);
Socket that wraps every call to AdvertisedWindowSize ().
static TypeId GetTypeId(void)
Get the type ID.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint32_t m_pktCount
Pkt count.
Class for inserting callbacks special points of the flow of TCP sockets.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
virtual Ptr< TcpSocketMsgBase > CreateSenderSocket(Ptr< Node > node)
Create and install the socket to install on the sender.
void SetExpectedSegmentSize(uint16_t seg)
Set the expected segment size.
uint16_t OldAdvertisedWindowSize(bool scale=true) const
The legacy code used for calculating the advertised window.
bool IsNull(void) const
Check for null implementation.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
void SetAppPktSize(uint32_t pktSize)
Set app packet size.
TcpSocketAdvertisedWindowProxy(const TcpSocketAdvertisedWindowProxy &other)
Copy-constructor.
void SetTransmitStart(Time startTime)
Set the initial time at which the application sends the first data packet.
static TypeId GetTypeId(void)
Get the type ID.
This test suite implements a Unit Test.
A general (TCP-aware) error model.
uint32_t m_pktSize
Packet size.
void InvalidAwndCb(uint16_t oldAwnd, uint16_t newAwnd)
Callback called for the update of the awnd.
uint32_t m_pktSize
Packet size.
Callback< void, uint16_t, uint16_t > InvalidAwndCallback
typedef for a cb
virtual void ConfigureEnvironment()
Change the configuration of the evironment.
void InvalidAwndCb(uint16_t oldAwnd, uint16_t newAwnd)
Callback called for the update of the awnd.
TcpAdvertisedWindowTestSuite()
virtual Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
uint16_t m_segmentSize
Test meta-information: size of the segments that are received.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
virtual Ptr< TcpSocketBase > Fork()
Call CopyObject<> to clone me.
virtual uint16_t AdvertisedWindowSize(bool scale=true) const
The amount of Rx window announced to the peer.
Hold an unsigned integer type.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
virtual uint16_t AdvertisedWindowSize(bool scale=true) const
The amount of Rx window announced to the peer.
uint32_t m_pktCount
Pkt count.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
double m_lossRatio
Loss ratio.
TcpAdvWindowOnLossTest(const std::string &desc, uint32_t size, uint32_t packets, std::vector< uint32_t > &toDrop)
Constructor.
TcpSocketAdvertisedWindowProxy()
Constructor.
void SetInvalidAwndCb(InvalidAwndCallback cb)
Set the invalid AdvWnd callback.
Ptr< UniformRandomVariable > m_prng
Random variable.
Test Suite for TCP adv window.
virtual Ptr< TcpSocketMsgBase > CreateSocket(Ptr< Node > node, TypeId socketType, TypeId congControl)
Create a socket.
virtual bool ShouldDrop(const Ipv4Header &ipHeader, const TcpHeader &tcpHeader, uint32_t packetSize)
Check if the packet should be dropped.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void AddSeqToKill(const SequenceNumber32 &seq)
Add the sequence number to the list of segments to be killed.
void SetAppPktCount(uint32_t pktCount)
Set app packet count.
InvalidAwndCallback m_inwalidAwndCb
Callback.
virtual void ConfigureEnvironment()
Change the configuration of the evironment.
std::vector< uint32_t > m_toDrop
Sequences to drop.
Test the new formula for calculating TCP's advertised window size.
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
General infrastructure for TCP testing.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
static const uint32_t packetSize
virtual Ptr< TcpSocketMsgBase > CreateReceiverSocket(Ptr< Node > node)
Create and install the socket to install on the receiver.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual Ptr< ErrorModel > CreateReceiverErrorModel()
Create and return the error model to install in the receiver node.
TcpDropRatioErrorModel(double dropRatio)
Constructor.
An error model that randomly drops a given rĂ¡tio of TCP segments.
void SetPropagationDelay(Time propDelay)
Propagation delay of the bottleneck link.
static TcpAdvertisedWindowTestSuite g_tcpAdvertisedWindowTestSuite
TcpAdvertisedWindowTest(const std::string &desc, uint32_t size, uint32_t packets, double lossRatio)
Constructor.
TypeId m_congControlTypeId
Congestion control.