18 #include "ns3/abort.h"
20 #include "ns3/pcap-file.h"
21 #include "ns3/config.h"
22 #include "ns3/string.h"
23 #include "ns3/uinteger.h"
24 #include "ns3/boolean.h"
25 #include "ns3/data-rate.h"
26 #include "ns3/inet-socket-address.h"
27 #include "ns3/point-to-point-helper.h"
28 #include "ns3/csma-helper.h"
29 #include "ns3/internet-stack-helper.h"
30 #include "ns3/ipv4-global-routing-helper.h"
31 #include "ns3/ipv4-address-helper.h"
32 #include "ns3/packet-sink-helper.h"
33 #include "ns3/tcp-socket-factory.h"
34 #include "ns3/node-container.h"
35 #include "ns3/simulator.h"
36 #include "ns3tcp-socket-writer.h"
54 virtual void DoRun (
void);
64 Ns3TcpNoDelayTestCase::Ns3TcpNoDelayTestCase (
bool noDelay)
65 :
TestCase (
"Check that ns-3 TCP Nagle's algorithm works correctly and that we can turn it off."),
67 m_writeResults (false)
74 m_responses.Add (p->
GetSize ());
80 uint16_t sinkPort = 50000;
81 double sinkStopTime = 8;
82 double writerStopTime = 5;
83 double simStopTime = 10;
93 pointToPoint.SetChannelAttribute (
"Delay",
StringValue (
"2ms"));
96 devices = pointToPoint.Install (n0, n1);
102 address.
SetBase (
"10.1.1.0",
"255.255.255.252");
107 socketWriter->Setup (n0, sinkAddress);
117 apps.
Stop (sinkStopTimeObj);
119 Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
123 Config::SetDefault (
"ns3::TcpSocket::TcpNoDelay",
BooleanValue (m_noDelay));
126 Simulator::Schedule (
Seconds (1), &SocketWriter::Connect, socketWriter);
129 Simulator::Schedule (
Seconds (2), &SocketWriter::Write, socketWriter, 2680);
138 Simulator::Schedule (
Seconds (2.010), &SocketWriter::Write, socketWriter, 1);
148 Simulator::Schedule (
Seconds (2.012), &SocketWriter::Write, socketWriter, 535);
162 Simulator::Schedule (writerStopTimeObj, &SocketWriter::Close, socketWriter);
166 std::ostringstream oss;
169 oss <<
"tcp-no-delay-on-test-case";
170 pointToPoint.EnablePcapAll (oss.str ());
174 oss <<
"tcp-no-delay-off-test-case";
175 pointToPoint.EnablePcapAll (oss.str ());
179 Simulator::Stop (simStopTimeObj);
181 Simulator::Destroy ();
184 NS_TEST_ASSERT_MSG_EQ (m_inputs.GetN (), m_responses.GetN (),
"Incorrect number of expected receive events");
185 for (uint32_t i = 0; i < m_responses.GetN (); i++)
187 uint32_t in = m_inputs.Get (i);
188 uint32_t out = m_responses.Get (i);
189 NS_TEST_ASSERT_MSG_EQ (in, out,
"Mismatch: expected " << in <<
" bytes, got " << out <<
" bytes");
199 Ns3TcpNoDelayTestSuite::Ns3TcpNoDelayTestSuite ()
holds a vector of ns3::Application pointers.
uint32_t AddApplication(Ptr< Application > application)
void SetStopTime(Time stop)
Specify application stop time.
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
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)
a polymophic address class
void InstallAll(void) const
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...
virtual void DoRun(void)
Implementation to actually run this test case.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
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.
ApplicationContainer Install(NodeContainer c) const
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
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