21 #include "ns3/abort.h" 
   23 #include "ns3/pcap-file.h" 
   24 #include "ns3/config.h" 
   25 #include "ns3/string.h" 
   26 #include "ns3/uinteger.h" 
   27 #include "ns3/data-rate.h" 
   28 #include "ns3/inet-socket-address.h" 
   29 #include "ns3/point-to-point-helper.h" 
   30 #include "ns3/internet-stack-helper.h" 
   31 #include "ns3/ipv4-global-routing-helper.h" 
   32 #include "ns3/ipv4-address-helper.h" 
   33 #include "ns3/packet-sink-helper.h" 
   34 #include "ns3/tcp-socket-factory.h" 
   35 #include "ns3/node-container.h" 
   36 #include "ns3/simulator.h" 
   37 #include "ns3/error-model.h" 
   38 #include "ns3/pointer.h" 
   39 #include "../ns3tcp/ns3tcp-socket-writer.h" 
   57   virtual void DoRun (
void);
 
   66 NscTcpLossTestCase1::NscTcpLossTestCase1 ()
 
   67   : 
TestCase (
"Check that nsc TCP survives loss of first two SYNs"),
 
   68     m_writeResults (false)
 
   75   m_responses.Add (p->
GetSize ());
 
   81   uint16_t sinkPort = 50000;
 
   82   double sinkStopTime = 40;  
 
   83   double writerStopTime = 30;  
 
   84   double simStopTime = 60;  
 
   94   pointToPoint.SetChannelAttribute (
"Delay", 
StringValue (
"200ms"));
 
   97   devices = pointToPoint.Install (n0, n1);
 
  100   internet.
SetTcp (
"ns3::NscTcpL4Protocol", 
"Library", 
StringValue (
"liblinux2.6.26.so"));
 
  104   address.
SetBase (
"10.1.1.0", 
"255.255.255.252");
 
  109   socketWriter->Setup (n0, sinkAddress);
 
  119   apps.
Stop (sinkStopTimeObj);
 
  121   Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
 
  124   Simulator::Schedule (
Seconds (2), &SocketWriter::Connect, socketWriter);
 
  125   Simulator::Schedule (
Seconds (10), &SocketWriter::Write, socketWriter, 500);
 
  127   Simulator::Schedule (writerStopTimeObj, &SocketWriter::Close, socketWriter);
 
  129   std::list<uint32_t> sampleList;
 
  131   sampleList.push_back (0);
 
  132   sampleList.push_back (1);
 
  136   devices.
Get (1)->SetAttribute (
"ReceiveErrorModel", 
PointerValue (pem));
 
  140       pointToPoint.EnablePcapAll (
"nsc-tcp-loss-test-case-1");
 
  141       pointToPoint.EnableAsciiAll (
"nsc-tcp-loss-test-case-1");
 
  144   Simulator::Stop (simStopTimeObj);
 
  146   Simulator::Destroy ();
 
  149   NS_TEST_ASSERT_MSG_EQ (m_inputs.GetN (), m_responses.GetN (), 
"Incorrect number of expected receive events");
 
  150   for (uint32_t i = 0; i < m_responses.GetN (); i++)
 
  152       uint32_t in = m_inputs.Get (i);
 
  153       uint32_t out = m_responses.Get (i);
 
  154       NS_TEST_ASSERT_MSG_EQ (in, out, 
"Mismatch:  expected " << in << 
" bytes, got " << out << 
" bytes");
 
  165   virtual void DoRun (
void);
 
  174 NscTcpLossTestCase2::NscTcpLossTestCase2 ()
 
  175   : 
TestCase (
"Check that nsc TCP survives loss of first data packet"),
 
  176     m_writeResults (false)
 
  183   m_responses.Add (p->
GetSize ());
 
  189   uint16_t sinkPort = 50000;
 
  190   double sinkStopTime = 40;  
 
  191   double writerStopTime = 12;  
 
  192   double simStopTime = 60;  
 
  202   pointToPoint.SetChannelAttribute (
"Delay", 
StringValue (
"200ms"));
 
  205   devices = pointToPoint.Install (n0, n1);
 
  208   internet.
SetTcp (
"ns3::NscTcpL4Protocol", 
"Library", 
StringValue (
"liblinux2.6.26.so"));
 
  212   address.
SetBase (
"10.1.1.0", 
"255.255.255.252");
 
  217   socketWriter->Setup (n0, sinkAddress);
 
  227   apps.
Stop (sinkStopTimeObj);
 
  229   Config::Connect (
"/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx",
 
  232   Simulator::Schedule (
Seconds (2), &SocketWriter::Connect, socketWriter);
 
  233   Simulator::Schedule (
Seconds (10), &SocketWriter::Write, socketWriter, 500);
 
  235   Simulator::Schedule (writerStopTimeObj, &SocketWriter::Close, socketWriter);
 
  237   std::list<uint32_t> sampleList;
 
  239   sampleList.push_back (2);
 
  243   devices.
Get (1)->SetAttribute (
"ReceiveErrorModel", 
PointerValue (pem));
 
  247       pointToPoint.EnablePcapAll (
"nsc-tcp-loss-test-case-2");
 
  248       pointToPoint.EnableAsciiAll (
"nsc-tcp-loss-test-case-2");
 
  251   Simulator::Stop (simStopTimeObj);
 
  253   Simulator::Destroy ();
 
  256   NS_TEST_ASSERT_MSG_EQ (m_inputs.GetN (), m_responses.GetN (), 
"Incorrect number of expected receive events");
 
  257   for (uint32_t i = 0; i < m_responses.GetN (); i++)
 
  259       uint32_t in = m_inputs.Get (i);
 
  260       uint32_t out = m_responses.Get (i);
 
  261       NS_TEST_ASSERT_MSG_EQ (in, out, 
"Mismatch:  expected " << in << 
" bytes, got " << out << 
" bytes");
 
  271 NscTcpLossTestSuite::NscTcpLossTestSuite ()
 
holds a vector of ns3::Application pointers. 
uint32_t AddApplication(Ptr< Application > application)
void SetStopTime(Time stop)
Specify application stop time. 
virtual void DoRun(void)
Implementation to actually run this test case. 
holds a vector of std::pair of Ptr<Ipv4> and interface index. 
hold variables of type string 
Ptr< NetDevice > Get(uint32_t i) const 
Get the Ptr<NetDevice> stored in this container at a given index. 
virtual void DoRun(void)
Implementation to actually run this test case. 
#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...
hold objects of type Ptr<T> 
void SetTcp(std::string tid)
set the Tcp stack which will not need any other parameter. 
void SetList(const std::list< uint32_t > &packetlist)
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