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"
65 virtual void DoSetup (
void);
66 virtual void DoRun (
void);
67 virtual void DoTeardown (
void);
82 void CwndTracer (uint32_t oldval, uint32_t newval);
83 void WriteUntilBufferFull (
Ptr<Socket> localSocket, uint32_t txSpace);
91 :
TestCase (
"Check the operation of the TCP state machine for several cases"),
93 m_totalTxBytes (200000),
96 m_writeResults (false),
99 m_tcpModel (
"ns3::TcpWestwood")
104 :
TestCase (
"Check the behaviour of TCP upon packet losses"),
105 m_testCase (testCase),
106 m_totalTxBytes (200000),
107 m_currentTxBytes (0),
109 m_writeResults (false),
111 m_needToClose (true),
112 m_tcpModel (tcpModel)
123 std::ostringstream oss;
124 oss <<
"/response-vectors/ns3tcp-loss-" <<
m_tcpModel <<
m_testCase <<
"-response-vectors.pcap";
170 uint8_t *buf =
new uint8_t[size];
174 uint32_t (tMicroSeconds % 1000000),
186 uint32_t tsSec, tsUsec, inclLen, origLen, readLen;
187 m_pcapFile.
Read (expected,
sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen);
191 uint8_t *actual =
new uint8_t[readLen];
194 uint32_t result = memcmp (actual, expected, readLen);
213 *(
m_osw->
GetStream ()) <<
"Moving cwnd from " << oldval <<
" to " << newval
215 <<
" seconds" << std::endl;
227 uint32_t dataOffset = m_currentTxBytes % 1040;
228 uint32_t toWrite = 1040 - dataOffset;
230 toWrite = std::min (toWrite, left);
231 toWrite = std::min (toWrite, txAvail);
238 std::clog <<
"Submitting " << toWrite
239 <<
" bytes to TCP socket" << std::endl;
241 int amountSent = localSocket->
Send (0, toWrite, 0);
243 m_currentTxBytes += amountSent;
249 std::clog <<
"Close socket at "
252 localSocket->
Close ();
264 std::clog <<
"Starting flow at time "
288 std::ostringstream tcpModel;
290 if (m_tcpModel.compare(
"WestwoodPlus") == 0)
346 ipv4.
SetBase (
"10.1.3.0",
"255.255.255.0");
348 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
352 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
359 uint16_t servPort = 50000;
369 Ptr<Socket> localSocket = Socket::CreateSocket (s1r1.
Get (0), TcpSocketFactory::GetTypeId ());
370 localSocket->
Bind ();
381 (
"/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow",
387 std::list<uint32_t> sampleList;
395 sampleList.push_back (16);
398 sampleList.push_back (16);
399 sampleList.push_back (17);
402 sampleList.push_back (16);
403 sampleList.push_back (17);
404 sampleList.push_back (18);
407 sampleList.push_back (16);
408 sampleList.push_back (17);
409 sampleList.push_back (18);
410 sampleList.push_back (19);
426 std::ostringstream oss;
427 oss <<
"tcp-loss-" << m_tcpModel <<
m_testCase <<
"-test-case";
434 std::ostringstream oss2;
435 oss2 <<
"src/test/ns3tcp/Tcp" << m_tcpModel <<
"." << m_testCase <<
".log";
446 Simulator::Stop (
Seconds (1000));
448 Simulator::Destroy ();
461 Packet::EnablePrinting ();