20 #include "ns3/abort.h"
22 #include "ns3/pcap-file.h"
23 #include "ns3/config.h"
24 #include "ns3/string.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/data-rate.h"
27 #include "ns3/inet-socket-address.h"
28 #include "ns3/point-to-point-helper.h"
29 #include "ns3/csma-helper.h"
30 #include "ns3/internet-stack-helper.h"
31 #include "ns3/ipv4-global-routing-helper.h"
32 #include "ns3/ipv4-address-helper.h"
33 #include "ns3/packet-sink-helper.h"
34 #include "ns3/tcp-socket-factory.h"
35 #include "ns3/node-container.h"
36 #include "ns3/simulator.h"
37 #include "ns3tcp-socket-writer.h"
55 virtual void DoRun (
void);
64 Ns3TcpSocketTestCase1::Ns3TcpSocketTestCase1 ()
65 :
TestCase (
"Check that ns-3 TCP successfully transfers an application data write of various sizes (point-to-point)"),
66 m_writeResults (false)
73 m_responses.Add (p->
GetSize ());
79 uint16_t sinkPort = 50000;
80 double sinkStopTime = 40;
81 double writerStopTime = 30;
82 double simStopTime = 60;
92 pointToPoint.SetChannelAttribute (
"Delay",
StringValue (
"2ms"));
95 devices = pointToPoint.Install (n0, n1);
101 address.
SetBase (
"10.1.1.0",
"255.255.255.252");
106 socketWriter->Setup (n0, sinkAddress);
116 apps.
Stop (sinkStopTimeObj);
118 Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
121 Simulator::Schedule (
Seconds (2), &SocketWriter::Connect, socketWriter);
123 Simulator::Schedule (
Seconds (10), &SocketWriter::Write, socketWriter, 1);
125 Simulator::Schedule (
Seconds (12), &SocketWriter::Write, socketWriter, 10);
127 Simulator::Schedule (
Seconds (14), &SocketWriter::Write, socketWriter, 100);
129 Simulator::Schedule (
Seconds (16), &SocketWriter::Write, socketWriter, 1000);
132 Simulator::Schedule (writerStopTimeObj, &SocketWriter::Close, socketWriter);
136 pointToPoint.EnablePcapAll (
"tcp-socket-test-case-1");
139 Simulator::Stop (simStopTimeObj);
141 Simulator::Destroy ();
144 NS_TEST_ASSERT_MSG_EQ (m_inputs.GetN (), m_responses.GetN (),
"Incorrect number of expected receive events");
145 for (uint32_t i = 0; i < m_responses.GetN (); i++)
147 uint32_t in = m_inputs.Get (i);
148 uint32_t out = m_responses.Get (i);
149 NS_TEST_ASSERT_MSG_EQ (in, out,
"Mismatch: expected " << in <<
" bytes, got " << out <<
" bytes");
160 virtual void DoRun (
void);
169 Ns3TcpSocketTestCase2::Ns3TcpSocketTestCase2 ()
170 :
TestCase (
"Check to see that ns-3 TCP successfully transfers an application data write of various sizes (CSMA)"),
171 m_writeResults (false)
178 m_responses.Add (p->
GetSize ());
184 uint16_t sinkPort = 50000;
185 double sinkStopTime = 40;
186 double writerStopTime = 30;
187 double simStopTime = 60;
192 Config::SetDefault (
"ns3::TcpSocket::SegmentSize",
UintegerValue (1000));
204 devices = csma.
Install (nodes);
210 address.
SetBase (
"10.1.1.0",
"255.255.255.252");
215 socketWriter->Setup (n0, sinkAddress);
225 apps.
Stop (sinkStopTimeObj);
227 Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
230 Simulator::Schedule (
Seconds (2), &SocketWriter::Connect, socketWriter);
233 Simulator::Schedule (
Seconds (10), &SocketWriter::Write, socketWriter, 1);
235 Simulator::Schedule (
Seconds (12), &SocketWriter::Write, socketWriter, 10);
237 Simulator::Schedule (
Seconds (14), &SocketWriter::Write, socketWriter, 100);
239 Simulator::Schedule (
Seconds (16), &SocketWriter::Write, socketWriter, 1000);
242 Simulator::Schedule (
Seconds (16), &SocketWriter::Write, socketWriter, 1001);
245 Simulator::Schedule (writerStopTimeObj, &SocketWriter::Close, socketWriter);
251 Simulator::Stop (simStopTimeObj);
253 Simulator::Destroy ();
256 NS_TEST_ASSERT_MSG_EQ (m_inputs.GetN (), m_responses.GetN (),
"Incorrect number of expected receive events");
257 for (uint32_t i = 0; i < m_responses.GetN (); i++)
259 uint32_t in = m_inputs.Get (i);
260 uint32_t out = m_responses.Get (i);
261 NS_TEST_ASSERT_MSG_EQ (in, out,
"Mismatch: expected " << in <<
" bytes, got " << out <<
" bytes");
271 Ns3TcpSocketTestSuite::Ns3TcpSocketTestSuite ()
holds a vector of ns3::Application pointers.
uint32_t AddApplication(Ptr< Application > application)
void SetStopTime(Time stop)
Specify application stop time.
void SetChannelAttribute(std::string n1, const AttributeValue &v1)
holds a vector of std::pair of Ptr<Ipv4> and interface index.
hold variables of type string
#define NS_LOG_COMPONENT_DEFINE(name)
aggregate IP/TCP/UDP functionality to existing Nodes.
uint32_t GetSize(void) const
NetDeviceContainer Install(Ptr< Node > node) const
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
virtual void DoRun(void)
Implementation to actually run this test case.
a polymophic address class
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 ...
void InstallAll(void) const
Hold an unsigned integer type.
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
void Start(Time start)
Arrange for all of the Applications in this container to Start() at the Time given as a parameter...
keep track of a set of node pointers.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
build a set of CsmaNetDevice objects
virtual void DoRun(void)
Implementation to actually run this test case.
void Stop(Time stop)
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter...
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
ApplicationContainer Install(NodeContainer c) const
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetStartTime(Time start)
Specify application start time.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const