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: "
409 dev0.
Get (1)->SetAttribute (
"ReceiveErrorModel",
PointerValue (errN0));
413 dev1.
Get (0)->SetAttribute (
"ReceiveErrorModel",
PointerValue (errN1));
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 ();
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
holds a vector of ns3::Application pointers.
void LogComponentEnableAll(enum LogLevel level)
keep track of time values and allow control of global simulation resolution
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
holds a vector of std::pair of Ptr and interface index.
hold variables of type string
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
#define NS_ASSERT(condition)
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 Connect(std::string path, const CallbackBase &cb)
void StartFlow(Ptr< Socket > localSocket, Ipv4Address servAddress, uint16_t servPort)
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
#define NS_FATAL_ERROR(msg)
fatal error handling
void StartFlow(Ptr< Socket >, Ipv4Address, uint16_t)
virtual ~Ns3TcpStateTestCase()
void WriteUntilBufferFull(Ptr< Socket > localSocket, uint32_t txSpace)
Class for representing data rates.
double GetSeconds(void) const
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 ...
int64_t GetMicroSeconds(void) const
void InstallAll(void) const
Aggregate IPv4, IPv6, UDP, and TCP stacks to all nodes in the simulation.
hold objects of type ns3::Time
A class representing a pcap file.
void Read(uint8_t *const data, uint32_t maxBytes, uint32_t &tsSec, uint32_t &tsUsec, uint32_t &inclLen, uint32_t &origLen, uint32_t &readLen)
Read next packet from file.
Hold an unsigned integer type.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
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 TestCase.
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
virtual int Connect(const Address &address)=0
Initiate a connection to a remote host.
Ptr< Packet > Copy(void) const
uint32_t m_currentTxBytes
void SetDefault(std::string name, const AttributeValue &value)
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket.
keep track of a set of node pointers.
void WriteUntilBufferFull(Ptr< Socket >, uint32_t)
void SetList(const std::list< uint32_t > &packetlist)
const uint32_t PCAP_LINK_TYPE
virtual void DoSetup(void)
Implementation to do any local setup required for this TestCase.
void Init(uint32_t dataLinkType, uint32_t snapLen=SNAPLEN_DEFAULT, int32_t timeZoneCorrection=ZONE_DEFAULT, bool swapMode=false)
Initialize the pcap file associated with this object.
void Close(void)
Close the underlying file.
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
void SetSendCallback(Callback< void, Ptr< Socket >, uint32_t > sendCb)
Notify application when space in transmit buffer is added.
static Ns3TcpStateTestSuite ns3TcpLossTestSuite
bool IsStatusSuccess(void) const
void Open(std::string const &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
Ipv4 addresses are stored in host order in this class.
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...
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container.
hold objects of type ns3::DataRate
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
ApplicationContainer Install(NodeContainer c) const
Install an ns3::PacketSinkApplication on each node of the input container configured with all the att...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void EnableAsciiAll(std::string prefix)
Enable ascii trace output on each device (which is of the appropriate type) in the set of all nodes c...
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
uint32_t GetDataLinkType(void)
void Write(uint32_t tsSec, uint32_t tsUsec, uint8_t const *const data, uint32_t totalLen)
Write next packet to file.
virtual int Send(Ptr< Packet > p, uint32_t flags)=0
Send data (or dummy data) to the remote host.
virtual int Close(void)=0
Close a socket.
virtual uint32_t GetTxAvailable(void) const =0
Returns the number of bytes which can be sent in a single call to Send.
void Ipv4L3Tx(std::string context, Ptr< const Packet > packet, Ptr< Ipv4 > ipv4, uint32_t interface)
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
void LogComponentEnable(char const *name, enum LogLevel level)
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const
const uint32_t PCAP_SNAPLEN
std::string m_pcapFilename