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"
64 virtual void DoSetup (
void);
65 virtual void DoRun (
void);
66 virtual void DoTeardown (
void);
81 void CwndTracer (uint32_t oldval, uint32_t newval);
82 void WriteUntilBufferFull (
Ptr<Socket> localSocket, uint32_t txSpace);
90 :
TestCase (
"Check the operation of the TCP state machine for several cases"),
92 m_totalTxBytes (200000),
95 m_writeResults (false),
98 m_tcpModel (
"ns3::TcpTahoe")
103 :
TestCase (
"Check the behaviour of TCP upon packet losses"),
104 m_testCase (testCase),
105 m_totalTxBytes (200000),
106 m_currentTxBytes (0),
108 m_writeResults (false),
110 m_needToClose (true),
111 m_tcpModel (tcpModel)
122 std::ostringstream oss;
123 oss <<
"/response-vectors/ns3tcp-loss-" <<
m_tcpModel <<
m_testCase <<
"-response-vectors.pcap";
169 uint8_t *buf =
new uint8_t[size];
173 uint32_t (tMicroSeconds % 1000000),
185 uint32_t tsSec, tsUsec, inclLen, origLen, readLen;
186 m_pcapFile.
Read (expected,
sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen);
190 uint8_t *actual =
new uint8_t[readLen];
193 uint32_t result = memcmp (actual, expected, readLen);
212 *(
m_osw->
GetStream ()) <<
"Moving cwnd from " << oldval <<
" to " << newval
214 <<
" seconds" << std::endl;
226 uint32_t dataOffset = m_currentTxBytes % 1040;
227 uint32_t toWrite = 1040 - dataOffset;
229 toWrite = std::min (toWrite, left);
230 toWrite = std::min (toWrite, txAvail);
237 std::clog <<
"Submitting " << toWrite
238 <<
" bytes to TCP socket" << std::endl;
240 int amountSent = localSocket->
Send (0, toWrite, 0);
242 m_currentTxBytes += amountSent;
248 std::clog <<
"Close socket at "
251 localSocket->
Close ();
263 std::clog <<
"Starting flow at time "
287 std::ostringstream tcpModel;
333 ipv4.
SetBase (
"10.1.3.0",
"255.255.255.0");
335 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
339 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
346 uint16_t servPort = 50000;
356 Ptr<Socket> localSocket = Socket::CreateSocket (s1r1.
Get (0), TcpSocketFactory::GetTypeId ());
357 localSocket->
Bind ();
368 (
"/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow",
374 std::list<uint32_t> sampleList;
382 sampleList.push_back (16);
385 sampleList.push_back (16);
386 sampleList.push_back (17);
389 sampleList.push_back (16);
390 sampleList.push_back (17);
391 sampleList.push_back (18);
394 sampleList.push_back (16);
395 sampleList.push_back (17);
396 sampleList.push_back (18);
397 sampleList.push_back (19);
413 std::ostringstream oss;
414 oss <<
"tcp-loss-" << m_tcpModel <<
m_testCase <<
"-test-case";
421 std::ostringstream oss2;
422 oss2 <<
"src/test/ns3tcp/Tcp" << m_tcpModel <<
"." << m_testCase <<
".log";
433 Simulator::Stop (
Seconds (1000));
435 Simulator::Destroy ();
448 Packet::EnablePrinting ();