10#include "ns3/config.h"
11#include "ns3/csma-helper.h"
12#include "ns3/data-rate.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/simulator.h"
23#include "ns3/string.h"
24#include "ns3/tcp-socket-factory.h"
26#include "ns3/uinteger.h"
48 void DoRun()
override;
64 :
TestCase(
"Check that ns-3 TCP successfully transfers an application data write of various "
65 "sizes (point-to-point)"),
79 uint16_t sinkPort = 50000;
80 double sinkStopTime = 40;
81 double writerStopTime = 30;
82 double simStopTime = 60;
91 pointToPoint.SetDeviceAttribute(
"DataRate",
StringValue(
"5Mbps"));
92 pointToPoint.SetChannelAttribute(
"Delay",
StringValue(
"2ms"));
95 devices = pointToPoint.Install(n0, n1);
98 internet.InstallAll();
101 address.SetBase(
"10.1.1.0",
"255.255.255.252");
106 socketWriter->Setup(n0, sinkAddress);
107 n0->AddApplication(socketWriter);
108 socketWriter->SetStartTime(
Seconds(0.));
109 socketWriter->SetStopTime(writerStopTimeObj);
116 apps.
Stop(sinkStopTimeObj);
136 pointToPoint.EnablePcapAll(
"tcp-socket-test-case-1");
146 "Incorrect number of expected receive events");
153 "Mismatch: expected " << in <<
" bytes, got " << out <<
" bytes");
173 void DoRun()
override;
189 :
TestCase(
"Check to see that ns-3 TCP successfully transfers an application data write of "
190 "various sizes (CSMA)"),
191 m_writeResults(false)
204 uint16_t sinkPort = 50000;
205 double sinkStopTime = 40;
206 double writerStopTime = 30;
207 double simStopTime = 60;
220 csma.SetChannelAttribute(
"DataRate",
StringValue(
"5Mbps"));
221 csma.SetChannelAttribute(
"Delay",
StringValue(
"2ms"));
224 devices = csma.Install(
nodes);
227 internet.InstallAll();
230 address.SetBase(
"10.1.1.0",
"255.255.255.252");
235 socketWriter->Setup(n0, sinkAddress);
236 n0->AddApplication(socketWriter);
237 socketWriter->SetStartTime(
Seconds(0.));
238 socketWriter->SetStopTime(writerStopTimeObj);
245 apps.
Stop(sinkStopTimeObj);
269 csma.EnablePcapAll(
"tcp-socket-test-case-2",
false);
278 "Incorrect number of expected receive events");
285 "Mismatch: expected " << in <<
" bytes, got " << out <<
" bytes");
Tests of TCP implementations from the application/socket perspective using CSMA links.
TestVectors< uint32_t > m_inputs
Sent packets test vector.
TestVectors< uint32_t > m_responses
Received packets test vector.
bool m_writeResults
True if write PCAP files.
Ns3TcpSocketTestCaseCsma()
~Ns3TcpSocketTestCaseCsma() override
void SinkRx(std::string path, Ptr< const Packet > p, const Address &address)
Receive a TCP packet.
void DoRun() override
Implementation to actually run this TestCase.
Tests of TCP implementations from the application/socket perspective using point-to-point links.
Ns3TcpSocketTestCaseP2P()
~Ns3TcpSocketTestCaseP2P() override
TestVectors< uint32_t > m_responses
Received packets test vector.
TestVectors< uint32_t > m_inputs
Sent packets test vector.
void SinkRx(std::string path, Ptr< const Packet > p, const Address &address)
Receive a TCP packet.
void DoRun() override
Implementation to actually run this TestCase.
bool m_writeResults
True if write PCAP files.
TCP implementations from the application/socket perspective TestSuite.
a polymophic address class
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.
build a set of CsmaNetDevice objects
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
static Ipv4Address GetAny()
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
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.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes.
Build a set of PointToPointNetDevice objects.
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
static void Run()
Run the simulation.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
void Connect()
Connect the socket.
void Write(uint32_t numBytes)
Write to the socket.
void Close()
Close the socket.
Hold variables of type string.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
A simple way to store test vectors (for stimulus or from responses)
T Get(std::size_t i) const
Get the i'th test vector.
std::size_t GetN() const
Get the total number of test vectors.
std::size_t Add(T vector)
Simulation virtual time values and global simulation resolution.
Hold an unsigned integer type.
void SetDefault(std::string name, const AttributeValue &value)
void Connect(std::string path, const CallbackBase &cb)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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...
static Ns3TcpSocketTestSuite g_ns3TcpSocketTestSuite
Do not forget to allocate an instance of this TestSuite.
Ptr< PacketSink > sink
Pointer to the packet sink application.