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 using namespace ns3;
35 
36 NS_LOG_COMPONENT_DEFINE ("TcpHtcpTestSuite");
37 
45 {
46 public:
58  TcpHtcpIncrementTest (uint32_t cWnd, uint32_t segmentSize,
59  uint32_t segmentsAcked, Time lastCongestion, Time firstAck,
60  Time secondAck, uint32_t expectedCwnd, const std::string &name);
61 
62 private:
63  virtual void DoRun (void);
64 
65  uint32_t m_cWnd;
66  uint32_t m_segmentSize;
67  uint32_t m_segmentsAcked;
71  uint32_t m_expectedCwnd;
73 };
74 
76  uint32_t segmentsAcked, Time lastCongestion, Time firstAck,
77  Time secondAck, uint32_t expectedCwnd, const std::string &name)
78  : TestCase (name),
79  m_cWnd (cWnd),
80  m_segmentSize (segmentSize),
81  m_segmentsAcked (segmentsAcked),
82  m_lastCongestion (lastCongestion),
83  m_firstAck (firstAck),
84  m_secondAck (secondAck),
85  m_expectedCwnd (expectedCwnd)
86 {
87 }
88 
95 void
97 {
98  NS_LOG_FUNCTION (this);
99  m_state = CreateObject<TcpSocketState> ();
100 
101  m_state->m_cWnd = m_cWnd;
103 
104  Ptr<TcpHtcp> cong = CreateObject<TcpHtcp> ();
105  Time lastCongestion;
106 
107  NS_LOG_DEBUG ("m_cWnd: " << m_cWnd << " m_segmentSize: " << m_segmentSize <<
108  " m_segmentsAcked: " << m_segmentsAcked << " m_lastCongestion" << m_lastCongestion);
109  Simulator::Schedule (Time (m_lastCongestion), &TcpHtcp::GetSsThresh, cong,
111  lastCongestion = m_lastCongestion;
112  Simulator::Schedule (Time (m_firstAck), &TcpHtcp::PktsAcked, cong, m_state,
114  Simulator::Schedule (Time (m_secondAck), &TcpHtcp::PktsAcked, cong, m_state,
116 
117  Simulator::Run ();
118  NS_LOG_DEBUG ("Simulation ran for the scheduled events");
119 
120  cong->IncreaseWindow (m_state, m_segmentsAcked);
121  NS_LOG_DEBUG ( "m_cwnd from function: " << m_state->m_cWnd << " expected cWnd calculated: " << m_expectedCwnd);
122 
124  "CWnd has not updated correctly");
125 
126  Simulator::Destroy ();
127 }
128 
147 {
148 public:
150  : TestSuite ("tcp-htcp-test", UNIT)
151  {
152 
153  AddTestCase (
154  new TcpHtcpIncrementTest (38 * 536, 536, 38, ns3::MilliSeconds (1),
155  ns3::MilliSeconds (900), ns3::MilliSeconds (1000),
156  20383,"TcpHtcp increment test on cWnd "), TestCase::QUICK);
157  AddTestCase (
158  new TcpHtcpIncrementTest (38, 1, 100, ns3::MilliSeconds (1),
159  ns3::MilliSeconds (900), ns3::MilliSeconds (1100),
160  40,"TcpHtcp increment test on cWnd "), TestCase::QUICK);
161  AddTestCase (
162  new TcpHtcpIncrementTest (53 * 1446, 1446, 50, ns3::MilliSeconds (1),
163  ns3::MilliSeconds (900), ns3::MilliSeconds (1500),
164  76671,"TcpHtcp increment test on cWnd "), TestCase::QUICK);
165 
166  }
167 };
168 
170 
Testing the congestion avoidance increment on TcpHtcp.
virtual void DoRun(void)
Since the calculation depends on the throughput and its associated timing, we schedule a few exact ev...
Time m_secondAck
Second ACK time.
Time m_lastCongestion
Last congestion time.
uint32_t m_segmentsAcked
Segments already ACKed.
uint32_t m_cWnd
Congestion window.
uint32_t m_expectedCwnd
Expected cWnd.
Ptr< TcpSocketState > m_state
TCP socket state.
uint32_t m_segmentSize
Segment size.
TcpHtcpIncrementTest(uint32_t cWnd, uint32_t segmentSize, uint32_t segmentsAcked, Time lastCongestion, Time firstAck, Time secondAck, uint32_t expectedCwnd, const std::string &name)
Constructor.
Time m_firstAck
First ACK time.
TCP Htcp TestSuite.
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
A suite of tests to run.
Definition: test.h:1188
@ UNIT
This test suite implements a Unit Test.
Definition: test.h:1197
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
T Get(void) const
Get the underlying value.
Definition: traced-value.h:232
uint32_t segmentSize
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#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:141
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TcpHtcpTestSuite g_TcpHtcpTest
Static variable for test initialization.