23 #include "ns3/abort.h"
25 #include "ns3/pcap-file.h"
26 #include "ns3/config.h"
27 #include "ns3/string.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/data-rate.h"
30 #include "ns3/inet-socket-address.h"
31 #include "ns3/point-to-point-helper.h"
32 #include "ns3/internet-stack-helper.h"
33 #include "ns3/ipv4-global-routing-helper.h"
34 #include "ns3/ipv4-address-helper.h"
35 #include "ns3/packet-sink-helper.h"
36 #include "ns3/tcp-socket-factory.h"
37 #include "ns3/node-container.h"
38 #include "ns3/simulator.h"
39 #include "ns3/error-model.h"
40 #include "ns3/pointer.h"
65 virtual void DoSetup (
void);
66 virtual void DoRun (
void);
67 virtual void DoTeardown (
void);
88 :
TestCase (
"Check the operation of the TCP state machine for several cases"),
90 m_totalTxBytes (20000),
93 m_writeResults (false),
100 :
TestCase (
"Check the operation of the TCP state machine for several cases"),
101 m_testCase (testCase),
102 m_totalTxBytes (20000),
103 m_currentTxBytes (0),
105 m_writeResults (false),
118 std::ostringstream oss;
119 oss <<
"/response-vectors/ns3tcp-state" <<
m_testCase <<
"-response-vectors.pcap";
120 m_pcapFilename =
static_cast<std::string
> (NS_TEST_SOURCEDIR) + oss.str ();
165 uint8_t *buf =
new uint8_t[size];
169 uint32_t (tMicroSeconds % 1000000),
181 uint32_t tsSec, tsUsec, inclLen, origLen, readLen;
182 m_pcapFile.
Read (expected,
sizeof(expected), tsSec, tsUsec, inclLen, origLen, readLen);
184 uint8_t *actual =
new uint8_t[readLen];
187 uint32_t result = memcmp (actual, expected, readLen);
209 uint32_t dataOffset = m_currentTxBytes % 1040;
210 uint32_t toWrite = 1040 - dataOffset;
212 toWrite = std::min (toWrite, left);
213 toWrite = std::min (toWrite, txAvail);
220 std::clog <<
"Submitting "
221 << toWrite <<
" bytes to TCP socket" << std::endl;
223 int amountSent = localSocket->
Send (0, toWrite, 0);
225 m_currentTxBytes += amountSent;
231 std::clog <<
"Close socket at "
235 localSocket->
Close ();
247 std::clog <<
"Starting flow at time "
270 std::string tcpModel (
"ns3::TcpNewReno");
314 ipv4.
SetBase (
"10.1.3.0",
"255.255.255.0");
316 ipv4.
SetBase (
"10.1.2.0",
"255.255.255.0");
320 Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
327 uint16_t servPort = 50000;
330 sinkApps.
Start (Seconds (0.0));
331 sinkApps.
Stop (Seconds (100.0));
337 TcpSocketFactory::GetTypeId ());
338 localSocket->
Bind ();
340 localSocket, ipInterfs.
GetAddress (1), servPort);
349 std::list<uint32_t> dropListN0;
350 std::list<uint32_t> dropListN1;
351 std::string caseDescription;
356 caseDescription =
"Verify connection establishment";
360 caseDescription =
"Verify a bigger (100 pkts) transfer: Sliding window operation, etc.";
364 caseDescription =
"Survive a SYN lost";
365 dropListN0.push_back (0);
369 caseDescription =
"Survive a SYN+ACK lost";
370 dropListN1.push_back (0);
374 caseDescription =
"Survive a ACK (last packet in 3-way handshake) lost";
375 dropListN0.push_back (1);
379 caseDescription =
"Immediate FIN upon SYN_RCVD";
381 dropListN0.push_back (1);
382 Simulator::Schedule (Seconds (0.002), &Socket::Close, localSocket);
386 caseDescription =
"Simulated simultaneous close";
387 dropListN1.push_back (5);
391 caseDescription =
"FIN check 1: Loss of initiator's FIN. Wait until app close";
393 dropListN0.push_back (7);
394 Simulator::Schedule (Seconds (0.04), &Socket::Close, localSocket);
398 caseDescription =
"FIN check 2: Loss responder's FIN. FIN will be resent after last ack timeout";
399 dropListN1.push_back (6);
402 NS_FATAL_ERROR (
"Program fatal error: specified test case not supported: "
415 std::ostringstream oss;
416 oss <<
"tcp-state" <<
m_testCase <<
"-test-case";
426 *(osw->
GetStream ()) << std::setprecision (9) << std::fixed;
429 std::clog << std::endl <<
"Running TCP test-case " << m_testCase <<
": "
430 << caseDescription << std::endl;
435 Simulator::Stop (Seconds (1000));
437 Simulator::Destroy ();
451 Packet::EnablePrinting ();