|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
22 #include "ns3/abort.h"
24 #include "ns3/pcap-file.h"
25 #include "ns3/config.h"
26 #include "ns3/string.h"
27 #include "ns3/uinteger.h"
28 #include "ns3/data-rate.h"
29 #include "ns3/inet-socket-address.h"
30 #include "ns3/point-to-point-helper.h"
31 #include "ns3/internet-stack-helper.h"
32 #include "ns3/ipv4-global-routing-helper.h"
33 #include "ns3/ipv4-address-helper.h"
34 #include "ns3/packet-sink-helper.h"
35 #include "ns3/tcp-socket-factory.h"
36 #include "ns3/node-container.h"
37 #include "ns3/simulator.h"
38 #include "ns3/error-model.h"
39 #include "ns3/pointer.h"
41 #include "ns3/tcp-westwood.h"
42 #include "ns3/tcp-header.h"
78 virtual void DoSetup (
void);
79 virtual void DoRun (
void);
80 virtual void DoTeardown (
void);
95 void CwndTracer (uint32_t oldval, uint32_t newval);
104 :
TestCase (
"Check the operation of the TCP state machine for several cases"),
106 m_totalTxBytes (200000),
107 m_currentTxBytes (0),
111 m_needToClose (true),
112 m_tcpModel (
"ns3::TcpWestwood")
117 :
TestCase (
"Check the behaviour of TCP upon packet losses"),
118 m_testCase (testCase),
119 m_totalTxBytes (200000),
120 m_currentTxBytes (0),
124 m_needToClose (true),
125 m_tcpModel (tcpModel)
143 std::ostringstream oss;
156 "Wrong response vectors in directory: opening " <<
193 uint32_t (tMicroSeconds % 1000000),
203 uint32_t tsSec, tsUsec, inclLen, origLen, readLen;
204 m_pcapFile.
Read (expectedBuffer,
sizeof(expectedBuffer), tsSec, tsUsec, inclLen, origLen, readLen);
208 uint8_t *actual =
new uint8_t[readLen];
209 received->
CopyData (actual, readLen);
211 int result = memcmp (actual, expectedBuffer, readLen);
213 TcpHeader expectedHeader, receivedHeader;
214 Ptr<Packet> expected = Create<Packet> (expectedBuffer, readLen);
219 NS_LOG_DEBUG (
"Expected " << expectedHeader <<
" received: " << receivedHeader);
238 *(
m_osw->
GetStream ()) <<
"Moving cwnd from " << oldval <<
" to " << newval
240 <<
" seconds" << std::endl;
253 uint32_t toWrite = 1040 - dataOffset;
256 toWrite =
std::min (toWrite, txAvail);
263 std::clog <<
"Submitting " << toWrite
264 <<
" bytes to TCP socket" << std::endl;
266 int amountSent = localSocket->
Send (0, toWrite, 0);
274 std::clog <<
"Close socket at "
277 localSocket->
Close ();
289 std::clog <<
"Starting flow at time "
315 std::ostringstream tcpModel;
371 ipv4.
SetBase (
"10.1.3.0",
"255.255.255.0");
373 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
377 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
384 uint16_t servPort = 50000;
394 Ptr<Socket> localSocket = Socket::CreateSocket (s1r1.
Get (0), TcpSocketFactory::GetTypeId ());
395 localSocket->
Bind ();
406 (
"/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow",
412 std::list<uint32_t> sampleList;
420 sampleList.push_back (16);
423 sampleList.push_back (16);
424 sampleList.push_back (17);
427 sampleList.push_back (16);
428 sampleList.push_back (17);
429 sampleList.push_back (18);
432 sampleList.push_back (16);
433 sampleList.push_back (17);
434 sampleList.push_back (18);
435 sampleList.push_back (19);
451 std::ostringstream oss;
459 std::ostringstream oss2;
471 Simulator::Stop (
Seconds (1000));
473 Simulator::Destroy ();
486 SetDataDir (
"src/test/ns3tcp/response-vectors");
487 Packet::EnablePrinting ();
void StartFlow(Ptr< Socket > localSocket, Ipv4Address servAddress, uint16_t servPort)
holds a vector of ns3::NetDevice pointers
void StartFlow(Ptr< Socket >, Ipv4Address, uint16_t)
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
AttributeValue implementation for DataRate.
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
void Ipv4L3Tx(std::string context, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
std::string m_pcapFilename
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
void WriteUntilBufferFull(Ptr< Socket >, uint32_t)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
AttributeValue implementation for Boolean.
@ LOG_LEVEL_INFO
LOG_INFO and above.
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
static Ns3TcpLossTestSuite ns3TcpLossTestSuite
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
@ LOG_LEVEL_ALL
Print everything.
uint32_t GetDataLinkType(void)
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
void LogComponentEnableAll(enum LogLevel level)
Enable the logging output for all registered log components.
NetDeviceContainer Install(NodeContainer c)
Ipv4 addresses are stored in host order in this class.
Hold objects of type Ptr<T>.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
void InstallAll(void) const
Aggregate IPv4, IPv6, UDP, and TCP stacks to all nodes in the simulation.
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Hold variables of type enum.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
A class representing a pcap file.
void Write(uint32_t tsSec, uint32_t tsUsec, uint8_t const *const data, uint32_t totalLen)
Write next packet to file.
bool IsStatusSuccess(void) const
Check if all tests passed.
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ptr< OutputStreamWrapper > m_osw
virtual void DoRun(void)
Implementation to actually run this TestCase.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Class for representing data rates.
void Open(std::string const &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
AttributeValue implementation for TypeId.
void SetList(const std::list< uint32_t > &packetlist)
void WriteUntilBufferFull(Ptr< Socket > localSocket, uint32_t txSpace)
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
int64_t GetMicroSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
uint32_t m_currentTxBytes
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
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.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void CwndTracer(uint32_t oldval, uint32_t newval)
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
Simulation virtual time values and global simulation resolution.
virtual int Close(void)=0
Close a socket.
virtual ~Ns3TcpLossTestCase()
const uint32_t PCAP_SNAPLEN
virtual uint32_t GetTxAvailable(void) const =0
Returns the number of bytes which can be sent in a single call to Send.
@ LOG_LEVEL_DEBUG
LOG_DEBUG and above.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Hold variables of type string.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Manage ASCII trace files for device models.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
void Connect(std::string path, const CallbackBase &cb)
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter.
std::string CreateDataDirFilename(std::string filename)
Construct the full path to a file in the data directory.
Time Seconds(double value)
Construct a Time in the indicated unit.
@ LOG_PREFIX_FUNC
Prefix all trace prints with function.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
holds a vector of ns3::Application pointers.
AttributeValue implementation for Time.
Build a set of PointToPointNetDevice objects.
static TypeId GetTypeId(void)
Get the type ID.
keep track of a set of node pointers.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
static void CwndTracer(Ptr< OutputStreamWrapper > stream, uint32_t oldval, uint32_t newval)
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.
aggregate IP/TCP/UDP functionality to existing Nodes.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
const uint32_t PCAP_LINK_TYPE
void Close(void)
Close the underlying file.