A Discrete-Event Network Simulator
API
tcp-htcp-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2015 ResiliNets, ITTC, University of Kansas
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Amir Modarresi <amodarresi@ittc.ku.edu>
19 
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  *
26  */
27 
28 #include "ns3/test.h"
29 #include "ns3/log.h"
30 #include "ns3/tcp-congestion-ops.h"
31 #include "ns3/tcp-socket-base.h"
32 #include "ns3/tcp-htcp.h"
33 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("TcpHtcpTestSuite");
37 
42 {
43 public:
44  TcpHtcpIncrementTest (uint32_t cWnd, uint32_t segmentSize,
45  uint32_t segmentsAcked, Time lastCongestion, Time firstAck,
46  Time secondAck, uint32_t expectedCwnd, const std::string &name);
47 
48 private:
49  virtual void DoRun (void);
50 
51  uint32_t m_cWnd;
52  uint32_t m_segmentSize;
53  uint32_t m_segmentsAcked;
57  uint32_t m_expectedCwnd;
59 };
60 
61 TcpHtcpIncrementTest::TcpHtcpIncrementTest (uint32_t cWnd, uint32_t segmentSize,
62  uint32_t segmentsAcked, Time lastCongestion, Time firstAck,
63  Time secondAck, uint32_t expectedCwnd, const std::string &name)
64  : TestCase (name),
65  m_cWnd (cWnd),
66  m_segmentSize (segmentSize),
67  m_segmentsAcked (segmentsAcked),
68  m_lastCongestion (lastCongestion),
69  m_firstAck (firstAck),
70  m_secondAck (secondAck),
71  m_expectedCwnd (expectedCwnd)
72 {
73 }
74 
81 void
83 {
84  NS_LOG_FUNCTION (this);
85  m_state = CreateObject<TcpSocketState> ();
86 
87  m_state->m_cWnd = m_cWnd;
88  m_state->m_segmentSize = m_segmentSize;
89 
90  Ptr<TcpHtcp> cong = CreateObject<TcpHtcp> ();
91  Time lastCongestion;
92 
93  NS_LOG_DEBUG ("m_cWnd: " << m_cWnd << " m_segmentSize: " << m_segmentSize <<
94  " m_segmentsAcked: " << m_segmentsAcked << " m_lastCongestion" << m_lastCongestion);
96  m_state, m_state->m_cWnd);
97  lastCongestion = m_lastCongestion;
102 
103  Simulator::Run ();
104  NS_LOG_DEBUG ("Simulation ran for the scheduled events");
105 
106  cong->IncreaseWindow (m_state, m_segmentsAcked);
107  NS_LOG_DEBUG ( "m_cwnd from function: " << m_state->m_cWnd << " expected cWnd calculated: " << m_expectedCwnd);
108 
110  "CWnd has not updated correctly");
111 
113 }
114 
115 /* The following tests simulate conditions after a congestion event and
116  * return to 1/2 ssthresh. After that, two acks are scheduled and the
117  * value of the cWnd is compared at the end of the event.
118  * The values in each test have been chosen randomly. The first test
119  * simulates receiving acks for 38 packets with segmentSize=536,
120  * the second one receives ack for 100 packets with segmentSize=1 and
121  * the third one receives ack for 50 segment with segmentSize=1446.
122  * The resulting cWnd values of 20383, 40 and 76671 have been
123  * calculated by hand from the algorithm for their expected values.
124  */
125 
126 static class TcpHtcpTestSuite : public TestSuite
127 {
128 public:
130  : TestSuite ("tcp-htcp-test", UNIT)
131  {
132 
133  AddTestCase (
134  new TcpHtcpIncrementTest (38 * 536, 536, 38, ns3::MilliSeconds (1),
135  ns3::MilliSeconds (900), ns3::MilliSeconds (1000),
136  20383,"TcpHtcp increment test on cWnd "), TestCase::QUICK);
137  AddTestCase (
138  new TcpHtcpIncrementTest (38, 1, 100, ns3::MilliSeconds (1),
139  ns3::MilliSeconds (900), ns3::MilliSeconds (1100),
140  40,"TcpHtcp increment test on cWnd "), TestCase::QUICK);
141  AddTestCase (
142  new TcpHtcpIncrementTest (53 * 1446, 1446, 50, ns3::MilliSeconds (1),
143  ns3::MilliSeconds (900), ns3::MilliSeconds (1500),
144  76671,"TcpHtcp increment test on cWnd "), TestCase::QUICK);
145 
146  }
147 } g_TcpHtcpTest;
148 
149 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-htcp.cc:203
static void Run(void)
Run the simulation.
Definition: simulator.cc:201
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
encapsulates test code
Definition: test.h:1147
This test suite implements a Unit Test.
Definition: test.h:1343
Testing the congestion avoidance increment on TcpHtcp.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:161
TcpHtcpIncrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time lastCongestion, Time firstAck, Time secondAck, uint32_t expectedCwnd, const std::string &name)
virtual void DoRun(void)
Since the calculation depends on the throughput and its associated timing, we schedule a few exact ev...
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:165
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< TcpSocketState > m_state
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
Definition: tcp-htcp.cc:181
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
ns3::TcpHtcpTestSuite g_TcpHtcpTest