10#include "ns3/config.h"
11#include "ns3/data-rate.h"
12#include "ns3/error-model.h"
13#include "ns3/inet-socket-address.h"
14#include "ns3/internet-stack-helper.h"
15#include "ns3/ipv4-address-helper.h"
16#include "ns3/ipv4-global-routing-helper.h"
18#include "ns3/node-container.h"
19#include "ns3/packet-sink-helper.h"
20#include "ns3/pcap-file.h"
21#include "ns3/point-to-point-helper.h"
22#include "ns3/pointer.h"
23#include "ns3/simulator.h"
24#include "ns3/string.h"
25#include "ns3/tcp-header.h"
26#include "ns3/tcp-socket-factory.h"
27#include "ns3/tcp-westwood-plus.h"
29#include "ns3/uinteger.h"
77 void DoRun()
override;
130 :
TestCase(
"Check the operation of the TCP state machine for several cases"),
132 m_totalTxBytes(200000),
138 m_tcpModel(
"ns3::TcpWestwoodPlus")
143 :
TestCase(
"Check the behaviour of TCP upon packet losses"),
144 m_testCase(testCase),
145 m_totalTxBytes(200000),
170 std::ostringstream oss;
183 "Wrong response vectors in directory: opening " <<
m_pcapFilename);
202 received->RemoveHeader(ipHeader);
234 .
Read(expectedBuffer,
sizeof(expectedBuffer), tsSec, tsUsec, inclLen, origLen, readLen);
238 auto actual =
new uint8_t[readLen];
239 received->CopyData(actual, readLen);
241 int result = memcmp(actual, expectedBuffer, readLen);
247 expected->RemoveHeader(expectedHeader);
248 received->RemoveHeader(receivedHeader);
250 NS_LOG_DEBUG(
"Expected " << expectedHeader <<
" received: " << receivedHeader);
261 "Expected data comparison error: " <<
m_tcpModel <<
"-"
272 *(
m_osw->GetStream()) <<
"Moving cwnd from " << oldval <<
" to " << newval <<
" at time "
286 uint32_t toWrite = 1040 - dataOffset;
287 uint32_t txAvail = localSocket->GetTxAvailable();
288 toWrite = std::min(toWrite, left);
289 toWrite = std::min(toWrite, txAvail);
296 std::clog <<
"Submitting " << toWrite <<
" bytes to TCP socket" << std::endl;
298 int amountSent = localSocket->Send(
nullptr, toWrite, 0);
308 localSocket->Close();
341 std::ostringstream tcpModel;
373 internet.InstallAll();
386 ipv4.SetBase(
"10.1.3.0",
"255.255.255.0");
388 ipv4.SetBase(
"10.1.2.0",
"255.255.255.0");
399 uint16_t servPort = 50000;
426 std::list<uint32_t> sampleList;
434 sampleList.push_back(16);
437 sampleList.push_back(16);
438 sampleList.push_back(17);
441 sampleList.push_back(16);
442 sampleList.push_back(17);
443 sampleList.push_back(18);
446 sampleList.push_back(16);
447 sampleList.push_back(17);
448 sampleList.push_back(18);
449 sampleList.push_back(19);
457 pem->SetList(sampleList);
465 std::ostringstream oss;
469 p2p.EnablePcapAll(oss.str());
470 p2p.EnableAsciiAll(oss.str());
473 std::ostringstream oss2;
479 *(
m_osw->GetStream()) << std::setprecision(9) << std::fixed;
480 p2p.EnableAsciiAll(
m_osw);
505 SetDataDir(
"src/test/ns3tcp/response-vectors");
Tests of TCP implementation loss behavior.
void CwndTracer(uint32_t oldval, uint32_t newval)
CWND trace.
void DoSetup() override
Implementation to do any local setup required for this TestCase.
void DoRun() override
Implementation to actually run this TestCase.
uint32_t m_currentTxBytes
Current number of bytes sent.
void StartFlow(Ptr< Socket > localSocket, Ipv4Address servAddress, uint16_t servPort)
Start transmitting a TCP flow.
PcapFile m_pcapFile
The PCAP ffile.
bool m_writeVectors
True if response vectors have to be written (and not read).
uint32_t m_testCase
Testcase number.
Ptr< OutputStreamWrapper > m_osw
The output stream.
bool m_writeResults
True if write PCAP files.
bool m_writeLogging
True if write logging.
uint32_t m_totalTxBytes
Total number of bytes to send.
void WriteUntilBufferFull(Ptr< Socket > localSocket, uint32_t txSpace)
Write to the socket until the buffer is full.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
std::string m_pcapFilename
The PCAP filename.
void Ipv4L3Tx(std::string context, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
Check that the transmitted packets are consistent with the trace.
~Ns3TcpLossTestCase() override
std::string m_tcpModel
The TCP model name.
bool m_needToClose
Check if the sending socket need to be closed.
TCP implementation loss behavior TestSuite.
holds a vector of ns3::Application pointers.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
Manage ASCII trace files for device models.
Ptr< OutputStreamWrapper > CreateFileStream(std::string filename, std::ios::openmode filemode=std::ios::out)
Create and initialize an output stream object we'll use to write the traced bits.
Class for representing data rates.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Ipv4 addresses are stored in host order in this class.
static Ipv4Address GetAny()
static void PopulateRoutingTables()
Build a routing database and initialize the routing tables of the nodes in the simulation.
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void Add(const NodeContainer &nc)
Append the contents of another NodeContainer to the end of this container.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
static void EnablePrinting()
Enable printing packets metadata.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
A class representing a pcap file.
void Close()
Close the underlying file.
void Open(const std::string &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
uint32_t GetDataLinkType()
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
void Read(uint8_t *const data, uint32_t maxBytes, uint32_t &tsSec, uint32_t &tsUsec, uint32_t &inclLen, uint32_t &origLen, uint32_t &readLen)
Read next packet from file.
void Init(uint32_t dataLinkType, uint32_t snapLen=SNAPLEN_DEFAULT, int32_t timeZoneCorrection=ZONE_DEFAULT, bool swapMode=false, bool nanosecMode=false)
Initialize the pcap file associated with this object.
void Write(uint32_t tsSec, uint32_t tsUsec, const uint8_t *const data, uint32_t totalLen)
Write next packet to file.
Build a set of PointToPointNetDevice objects.
AttributeValue implementation for Pointer.
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static Time Now()
Return the current simulation virtual time.
static void Run()
Run the simulation.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
static Ptr< Socket > CreateSocket(Ptr< Node > node, TypeId tid)
This method wraps the creation of sockets that is performed on a given node by a SocketFactory specif...
Hold variables of type string.
static TypeId GetTypeId()
Get the type ID.
static TypeId GetTypeId()
Get the type ID.
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
bool IsStatusSuccess() const
Check if all tests passed.
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Simulation virtual time values and global simulation resolution.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
int64_t GetMicroSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
Hold an unsigned integer type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
void SetDefault(std::string name, const AttributeValue &value)
void Connect(std::string path, const CallbackBase &cb)
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void LogComponentEnable(const std::string &name, LogLevel level)
Enable the logging output associated with that log component.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
@ LOG_LEVEL_ALL
Print everything.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
@ LOG_LEVEL_DEBUG
LOG_DEBUG and above.
@ LOG_LEVEL_INFO
LOG_INFO and above.
void LogComponentEnableAll(LogLevel level)
Enable the logging output for all registered log components.
const uint32_t PCAP_LINK_TYPE
Some large random number – we use to verify data was written by this program.
const bool WRITE_VECTORS
Set to true to write response vectors.
const bool WRITE_PCAP
Set to true to write out pcap.
static Ns3TcpLossTestSuite g_ns3TcpLossTestSuite
Do not forget to allocate an instance of this TestSuite.
const bool WRITE_LOGGING
Set to true to write logging.
const uint32_t PCAP_SNAPLEN
Don't bother to save much data.
Ptr< PacketSink > sink
Pointer to the packet sink application.