20 #include "ns3/abort.h" 
   22 #include "ns3/pcap-file.h" 
   23 #include "ns3/config.h" 
   24 #include "ns3/string.h" 
   25 #include "ns3/uinteger.h" 
   26 #include "ns3/data-rate.h" 
   27 #include "ns3/inet-socket-address.h" 
   28 #include "ns3/point-to-point-helper.h" 
   29 #include "ns3/internet-stack-helper.h" 
   30 #include "ns3/ipv4-global-routing-helper.h" 
   31 #include "ns3/ipv4-address-helper.h" 
   32 #include "ns3/packet-sink-helper.h" 
   33 #include "ns3/tcp-socket-factory.h" 
   34 #include "ns3/simulator.h" 
   85   virtual void StartApplication (
void);
 
   86   virtual void StopApplication (
void);
 
   88   void ScheduleTx (
void);
 
   89   void SendPacket (
void);
 
   93   uint32_t        m_packetSize;
 
   98   uint32_t        m_packetsSent;
 
  101 SimpleSource::SimpleSource ()
 
  113 SimpleSource::~SimpleSource()
 
  123   m_packetSize = packetSize;
 
  124   m_nPackets = nPackets;
 
  125   m_dataRate = dataRate;
 
  145       Simulator::Cancel (m_sendEvent);
 
  155 SimpleSource::SendPacket (
void)
 
  157   Ptr<Packet> packet = Create<Packet> (m_packetSize);
 
  158   m_socket->
Send (packet);
 
  160   if (++m_packetsSent < m_nPackets)
 
  167 SimpleSource::ScheduleTx (
void)
 
  171       Time tNext (Seconds (m_packetSize * 8 / static_cast<double> (m_dataRate.
GetBitRate ())));
 
  172       m_sendEvent = Simulator::Schedule (tNext, &SimpleSource::SendPacket, 
this);
 
  183   virtual void DoRun (
void);
 
  194   void CwndChange (uint32_t oldCwnd, uint32_t newCwnd);
 
  197 Ns3TcpCwndTestCase1::Ns3TcpCwndTestCase1 ()
 
  198   : 
TestCase (
"Check to see that the ns-3 TCP congestion window works as expected against liblinux2.6.26.so"),
 
  199     m_writeResults (false)
 
  203 Ns3TcpCwndTestCase1::~Ns3TcpCwndTestCase1 ()
 
  208 Ns3TcpCwndTestCase1::CwndChange (uint32_t oldCwnd, uint32_t newCwnd)
 
  212   event.m_oldCwnd = oldCwnd;
 
  213   event.m_newCwnd = newCwnd;
 
  215   m_responses.Add (event);
 
  243   devices = pointToPoint.
Install (nodes);
 
  256   std::string nscStack = 
"liblinux2.6.26.so";
 
  257   stack.
SetTcp (
"ns3::NscTcpL4Protocol", 
"Library", 
StringValue (
"liblinux2.6.26.so"));
 
  265   address.
SetBase (
"10.1.1.0", 
"255.255.255.252");
 
  273   uint16_t sinkPort = 8080;
 
  300   Ptr<Socket> ns3TcpSocket = Socket::CreateSocket (nodes.
Get (0), TcpSocketFactory::GetTypeId ());
 
  304   app->Setup (ns3TcpSocket, sinkAddress, 1040, 10, 
DataRate (
"5Mbps"));
 
  331   Simulator::Destroy ();
 
  347   const uint32_t MSS = 536;
 
  348   const uint32_t N_EVENTS = 21;
 
  352   NS_TEST_ASSERT_MSG_EQ (m_responses.GetN (), N_EVENTS, 
"Unexpectedly low number of cwnd change events");
 
  356   for (uint32_t i = 1, from = MSS, to = MSS * 2; i < N_EVENTS; ++i, from += MSS, to += MSS)
 
  358       event = m_responses.Get (i);
 
  359       NS_TEST_ASSERT_MSG_EQ (event.m_oldCwnd, from, 
"Wrong old cwnd value in cwnd change event " << i);
 
  360       NS_TEST_ASSERT_MSG_EQ (event.m_newCwnd, to, 
"Wrong new cwnd value in cwnd change event " << i);
 
  386   virtual void DoRun (
void);
 
  387   void VerifyCwndRun (uint32_t beginIdx, uint32_t endIdx, uint32_t initialCwnd, uint32_t mss);
 
  398   void CwndChange (uint32_t oldCwnd, uint32_t newCwnd);
 
  401 Ns3TcpCwndTestCase2::Ns3TcpCwndTestCase2 ()
 
  402   : 
TestCase (
"Check to see that the ns-3 TCP congestion window works as expected for out-of-order packet delivery"),
 
  403     m_writeResults (false)
 
  407 Ns3TcpCwndTestCase2::~Ns3TcpCwndTestCase2 ()
 
  412 Ns3TcpCwndTestCase2::CwndChange (uint32_t oldCwnd, uint32_t newCwnd)
 
  416   event.m_oldCwnd = oldCwnd;
 
  417   event.m_newCwnd = newCwnd;
 
  419   m_responses.Add (event);
 
  426   Config::SetDefault (
"ns3::DropTailQueue::MaxPackets", 
UintegerValue (4));
 
  457   ipv4.
SetBase (
"10.1.3.0", 
"255.255.255.0");
 
  459   ipv4.
SetBase (
"10.1.2.0", 
"255.255.255.0");
 
  461   ipv4.
SetBase (
"10.1.1.0", 
"255.255.255.0");
 
  465   Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
 
  468   uint16_t servPort = 50000;
 
  480   Ptr<Socket> ns3TcpSocket = Socket::CreateSocket (n0n1.
Get (0), TcpSocketFactory::GetTypeId ());
 
  485   app->Setup (ns3TcpSocket, sinkAddress, 1040, 1000, 
DataRate (
"1Mbps"));
 
  498   Simulator::Stop (
Seconds (4.4));
 
  500   Simulator::Destroy ();
 
  518   const uint32_t MSS = 536;
 
  519   const uint32_t N_EVENTS = 45;
 
  523   NS_TEST_ASSERT_MSG_EQ (m_responses.GetN (), N_EVENTS, 
"Unexpected number of cwnd change events");
 
  526   VerifyCwndRun (1, 10, 2 * MSS, MSS);
 
  529   event = m_responses.Get (10);
 
  530   NS_TEST_ASSERT_MSG_EQ (event.m_newCwnd, 8*MSS, 
"Wrong new cwnd value in cwnd change event " << 10);
 
  532   VerifyCwndRun (11, 13, 9 * MSS, MSS);
 
  536   NS_TEST_ASSERT_MSG_EQ (m_responses.Get (15).m_newCwnd, 9 * MSS, 
"Wrong new cwnd value in cwnd change event " << 15);
 
  539   VerifyCwndRun (16, 17, 10 * MSS, MSS);
 
  543   NS_TEST_ASSERT_MSG_EQ (m_responses.Get (19).m_newCwnd, 9 * MSS, 
"Wrong new cwnd value in cwnd change event " << 19);
 
  546   VerifyCwndRun (20, 22, 10 * MSS, MSS);
 
  550   NS_TEST_ASSERT_MSG_EQ (m_responses.Get (24).m_newCwnd, 10 * MSS, 
"Wrong new cwnd value in cwnd change event " << 24);  
 
  553   VerifyCwndRun (25, 29, 11 * MSS, MSS);
 
  556   NS_TEST_ASSERT_MSG_EQ (m_responses.Get (29).m_newCwnd, 5 * MSS, 
"Wrong new cwnd value in cwnd change event " << 29);  
 
  558   uint32_t cwnd = 5 * MSS;
 
  560   for (uint32_t i = 30; i < N_EVENTS; ++i)
 
  562       double adder = 
static_cast<double> (MSS * MSS) / cwnd;
 
  563       adder = std::max (1.0, adder);
 
  564       cwnd += 
static_cast<uint32_t
> (adder);    
 
  565       NS_TEST_ASSERT_MSG_EQ (m_responses.Get (i).m_newCwnd, cwnd, 
"Wrong new cwnd value in cwnd change event " << i); 
 
  570 Ns3TcpCwndTestCase2::VerifyCwndRun (uint32_t beginIdx, uint32_t endIdx, uint32_t initialCwnd, uint32_t mss)
 
  575   for(uint32_t i = beginIdx, to = initialCwnd; i < endIdx; ++i, to += mss)
 
  577       event = m_responses.Get (i);
 
  578       NS_TEST_ASSERT_MSG_EQ (event.m_newCwnd, to, 
"Wrong new cwnd value in cwnd change event " << i);      
 
  588 Ns3TcpCwndTestSuite::Ns3TcpCwndTestSuite ()
 
holds a vector of ns3::Application pointers. 
uint32_t AddApplication(Ptr< Application > application)
void SetStopTime(Time stop)
Specify application stop time. 
holds a vector of std::pair of Ptr<Ipv4> and interface index. 
hold variables of type string 
NetDeviceContainer Install(NodeContainer c)
#define NS_LOG_COMPONENT_DEFINE(name)
aggregate IP/TCP/UDP functionality to existing Nodes. 
A helper to make it easier to instantiate an ns3::PacketSinkApplication on a set of nodes...
bool IsRunning(void) const 
Build a set of PointToPointNetDevice objects. 
void SetDeviceAttribute(std::string name, const AttributeValue &value)
a polymophic address class 
A simple way to store test vectors (for stimulus or from responses) 
virtual void StopApplication(void)
Application specific shutdown code. 
Class for representing data rates. 
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 ...
void InstallAll(void) const 
The base class for all ns3 applications. 
hold objects of type ns3::Time 
virtual void StartApplication(void)
Application specific startup code. 
Hold an unsigned integer type. 
holds a vector of ns3::NetDevice pointers 
virtual void DoRun(void)
Implementation to actually run this test case. 
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 int Connect(const Address &address)=0
Initiate a connection to a remote host. 
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
virtual void DoRun(void)
Implementation to actually run this test case. 
virtual int Bind(const Address &address)=0
Allocate a local endpoint for this socket. 
keep track of a set of node pointers. 
void SetTcp(std::string tid)
set the Tcp stack which will not need any other parameter. 
uint64_t GetBitRate() const 
void Install(std::string nodeName) const 
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite. 
void SetChannelAttribute(std::string name, const AttributeValue &value)
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. 
void Add(NodeContainer other)
Append the contents of another NodeContainer to the end of this container. 
an identifier for simulation events. 
hold objects of type ns3::DataRate 
Ptr< Node > Get(uint32_t i) const 
Get the Ptr<Node> stored in this container at a given index. 
ApplicationContainer Install(NodeContainer c) const 
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds. 
A helper class to make life easier while doing simple IPv4 address assignment in scripts. 
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer. 
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. 
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