NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn-rtt-estimator.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 //
3 // Copyright (c) 2006 Georgia Tech Research Corporation
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 // Author: Rajib Bhattacharjea<raj.b@gatech.edu>
19 //
20 
21 // THIS IS A COPY OF rtt-estimator.cc from internet module with minor modifications
22 
23 // Ported from:
24 // Georgia Tech Network Simulator - Round Trip Time Estimation Class
25 // George F. Riley. Georgia Tech, Spring 2002
26 
27 // Implements several variations of round trip time estimators
28 
29 #include <iostream>
30 
31 #include "ndn-rtt-estimator.hpp"
32 #include "ns3/simulator.h"
33 #include "ns3/double.h"
34 #include "ns3/integer.h"
35 #include "ns3/uinteger.h"
36 #include "ns3/log.h"
37 
38 NS_LOG_COMPONENT_DEFINE("ndn.RttEstimator");
39 
40 namespace ns3 {
41 
42 namespace ndn {
43 
45 
46 TypeId
48 {
49  static TypeId tid =
50  TypeId("ns3::ndn::RttEstimator")
51  .SetParent<Object>()
52  .AddAttribute("MaxMultiplier", "Maximum RTO Multiplier", UintegerValue(64),
53  MakeUintegerAccessor(&RttEstimator::m_maxMultiplier),
54  MakeUintegerChecker<uint16_t>())
55  .AddAttribute("InitialEstimation", "Initial RTT estimation", TimeValue(Seconds(1.0)),
56  MakeTimeAccessor(&RttEstimator::m_initialEstimatedRtt), MakeTimeChecker())
57  .AddAttribute("MinRTO", "Minimum retransmit timeout value",
58  TimeValue(
59  Seconds(0.2)), // RFC2988 says min RTO=1 sec, but Linux uses 200ms. See
60  // http://www.postel.org/pipermail/end2end-interest/2004-November/004402.html
62  MakeTimeChecker())
63  .AddAttribute("MaxRTO", "Maximum retransmit timeout value", TimeValue(Seconds(200.0)),
65  MakeTimeChecker());
66  return tid;
67 }
68 
69 void
71 {
72  NS_LOG_FUNCTION(this << minRto);
73  m_minRto = minRto;
74 }
75 Time
77 {
78  return m_minRto;
79 }
80 
81 void
83 {
84  NS_LOG_FUNCTION(this << maxRto);
85  m_maxRto = maxRto;
86 }
87 Time
89 {
90  return m_maxRto;
91 }
92 
93 void
95 {
96  NS_LOG_FUNCTION(this << estimate);
97  m_currentEstimatedRtt = estimate;
98 }
99 Time
101 {
102  return m_currentEstimatedRtt;
103 }
104 
105 // RttHistory methods
106 RttHistory::RttHistory(SequenceNumber32 s, uint32_t c, Time t)
107  : seq(s)
108  , count(c)
109  , time(t)
110  , retx(false)
111 {
112  NS_LOG_FUNCTION(this);
113 }
114 
116  : seq(h.seq)
117  , count(h.count)
118  , time(h.time)
119  , retx(h.retx)
120 {
121  NS_LOG_FUNCTION(this);
122 }
123 
124 // Base class methods
125 
127  : m_next(1)
128  , m_nSamples(0)
129  , m_multiplier(1)
130  , m_history()
131 {
132  NS_LOG_FUNCTION(this);
133  // note next=1 everywhere since first segment will have sequence 1
134 
135  // We need attributes initialized here, not later, so use the
136  // ConstructSelf() technique documented in the manual
137  ObjectBase::ConstructSelf(AttributeConstructionList());
138  m_currentEstimatedRtt = m_initialEstimatedRtt;
139  NS_LOG_DEBUG("Initialize m_currentEstimatedRtt to " << m_currentEstimatedRtt.GetSeconds()
140  << " sec.");
141 }
142 
144  : Object(c)
145  , m_next(c.m_next)
146  , m_maxMultiplier(c.m_maxMultiplier)
147  , m_initialEstimatedRtt(c.m_initialEstimatedRtt)
148  , m_currentEstimatedRtt(c.m_currentEstimatedRtt)
149  , m_minRto(c.m_minRto)
150  , m_maxRto(c.m_maxRto)
151  , m_nSamples(c.m_nSamples)
152  , m_multiplier(c.m_multiplier)
153  , m_history(c.m_history)
154 {
155  NS_LOG_FUNCTION(this);
156 }
157 
159 {
160  NS_LOG_FUNCTION(this);
161 }
162 
163 TypeId
165 {
166  return GetTypeId();
167 }
168 
169 void
170 RttEstimator::SentSeq(SequenceNumber32 seq, uint32_t size)
171 {
172  NS_LOG_FUNCTION(this << seq << size);
173  // Note that a particular sequence has been sent
174  if (seq == m_next) { // This is the next expected one, just log at end
175  m_history.push_back(RttHistory(seq, size, Simulator::Now()));
176  m_next = seq + SequenceNumber32(size); // Update next expected
177  }
178  else { // This is a retransmit, find in list and mark as re-tx
179  for (RttHistory_t::iterator i = m_history.begin(); i != m_history.end(); ++i) {
180  if ((seq >= i->seq) && (seq < (i->seq + SequenceNumber32(i->count)))) { // Found it
181  i->retx = true;
182  // One final test..be sure this re-tx does not extend "next"
183  if ((seq + SequenceNumber32(size)) > m_next) {
184  m_next = seq + SequenceNumber32(size);
185  i->count = ((seq + SequenceNumber32(size)) - i->seq); // And update count in hist
186  }
187  break;
188  }
189  }
190  }
191 }
192 
193 Time
194 RttEstimator::AckSeq(SequenceNumber32 ackSeq)
195 {
196  NS_LOG_FUNCTION(this << ackSeq);
197  // An ack has been received, calculate rtt and log this measurement
198  // Note we use a linear search (O(n)) for this since for the common
199  // case the ack'ed packet will be at the head of the list
200  Time m = Seconds(0.0);
201  if (m_history.size() == 0)
202  return (m); // No pending history, just exit
203  RttHistory& h = m_history.front();
204  if (!h.retx && ackSeq >= (h.seq + SequenceNumber32(h.count))) { // Ok to use this sample
205  m = Simulator::Now() - h.time; // Elapsed time
206  Measurement(m); // Log the measurement
207  ResetMultiplier(); // Reset multiplier on valid measurement
208  }
209  // Now delete all ack history with seq <= ack
210  while (m_history.size() > 0) {
211  RttHistory& h = m_history.front();
212  if ((h.seq + SequenceNumber32(h.count)) > ackSeq)
213  break; // Done removing
214  m_history.pop_front(); // Remove
215  }
216  return m;
217 }
218 
219 void
221 {
222  NS_LOG_FUNCTION(this);
223  // Clear all history entries
224  m_next = 1;
225  m_history.clear();
226 }
227 
228 void
230 {
231  NS_LOG_FUNCTION(this);
232  m_multiplier = (m_multiplier * 2 < m_maxMultiplier) ? m_multiplier * 2 : m_maxMultiplier;
233  NS_LOG_DEBUG("Multiplier increased to " << m_multiplier);
234 }
235 
236 void
238 {
239  NS_LOG_FUNCTION(this);
240  m_multiplier = 1;
241 }
242 
243 void
245 {
246  NS_LOG_FUNCTION(this);
247  // Reset to initial state
248  m_next = 1;
249  m_currentEstimatedRtt = m_initialEstimatedRtt;
250  m_history.clear(); // Remove all info from the history
251  m_nSamples = 0;
252  ResetMultiplier();
253 }
254 
255 } // namespace ndn
256 } // namespace ns3
ns3::ndn::RttEstimator::m_nSamples
uint32_t m_nSamples
Definition: ndn-rtt-estimator.hpp:182
ns3::ndn::RttEstimator
Base class for all RTT Estimators.
Definition: ndn-rtt-estimator.hpp:61
ns3::ndn::RttEstimator::m_multiplier
uint16_t m_multiplier
Definition: ndn-rtt-estimator.hpp:183
ns3::ndn::RttEstimator::m_maxRto
Time m_maxRto
Definition: ndn-rtt-estimator.hpp:181
ns3::ndn::RttHistory::count
uint32_t count
Definition: ndn-rtt-estimator.hpp:49
ns3
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-app-link-service.cpp:32
ns3::ndn::RttEstimator::m_history
RttHistory_t m_history
Definition: ndn-rtt-estimator.hpp:184
ns3::ndn::RttHistory::retx
bool retx
Definition: ndn-rtt-estimator.hpp:51
ns3::ndn::RttEstimator::m_currentEstimatedRtt
Time m_currentEstimatedRtt
Definition: ndn-rtt-estimator.hpp:179
ns3::ndn::RttHistory::time
Time time
Definition: ndn-rtt-estimator.hpp:50
ns3::ndn::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(GlobalRouter)
ns3::ndn::RttHistory::seq
SequenceNumber32 seq
Definition: ndn-rtt-estimator.hpp:48
ns3::ndn::RttEstimator::~RttEstimator
virtual ~RttEstimator()
Definition: ndn-rtt-estimator.cpp:158
ns3::ndn::RttHistory::RttHistory
RttHistory(SequenceNumber32 s, uint32_t c, Time t)
Definition: ndn-rtt-estimator.cpp:106
ns3::ndn::RttEstimator::GetMinRto
Time GetMinRto(void) const
Get the Minimum RTO.
Definition: ndn-rtt-estimator.cpp:76
ndn::time
Definition: time-custom-clock.hpp:28
ns3::ndn::RttEstimator::RttEstimator
RttEstimator()
Definition: ndn-rtt-estimator.cpp:126
ns3::ndn::RttEstimator::GetCurrentEstimate
Time GetCurrentEstimate(void) const
gets the current RTT estimate.
Definition: ndn-rtt-estimator.cpp:100
ns3::ndn::RttEstimator::SentSeq
virtual void SentSeq(SequenceNumber32 seq, uint32_t size)
Note that a particular sequence has been sent.
Definition: ndn-rtt-estimator.cpp:170
ns3::ndn::RttEstimator::GetTypeId
static TypeId GetTypeId(void)
Definition: ndn-rtt-estimator.cpp:47
ns3::ndn::RttEstimator::Reset
virtual void Reset()
Resets the estimation to its initial state.
Definition: ndn-rtt-estimator.cpp:244
ndn-rtt-estimator.hpp
ns3::ndn::RttEstimator::AckSeq
virtual Time AckSeq(SequenceNumber32 ackSeq)
Note that a particular ack sequence has been received.
Definition: ndn-rtt-estimator.cpp:194
ns3::ndn::RttEstimator::ClearSent
virtual void ClearSent()
Clear all history entries.
Definition: ndn-rtt-estimator.cpp:220
ns3::ndn::RttEstimator::m_minRto
Time m_minRto
Definition: ndn-rtt-estimator.hpp:180
ns3::ndn::RttEstimator::SetMaxRto
void SetMaxRto(Time maxRto)
Sets the Maximum RTO.
Definition: ndn-rtt-estimator.cpp:82
ns3::ndn::RttHistory
Helper class to store RTT measurements.
Definition: ndn-rtt-estimator.hpp:43
ns3::ndn::RttEstimator::Measurement
virtual void Measurement(Time t)=0
Add a new measurement to the estimator.
ns3::ndn::RttEstimator::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Definition: ndn-rtt-estimator.cpp:164
ns3::ndn::RttEstimator::SetCurrentEstimate
void SetCurrentEstimate(Time estimate)
Sets the current RTT estimate (forcefully).
Definition: ndn-rtt-estimator.cpp:94
ns3::ndn::RttEstimator::GetMaxRto
Time GetMaxRto(void) const
Get the Maximum RTO.
Definition: ndn-rtt-estimator.cpp:88
ns3::ndn::RttEstimator::IncreaseMultiplier
virtual void IncreaseMultiplier()
Increase the estimation multiplier up to MaxMultiplier.
Definition: ndn-rtt-estimator.cpp:229
ns3::ndn::RttEstimator::SetMinRto
void SetMinRto(Time minRto)
Sets the Minimum RTO.
Definition: ndn-rtt-estimator.cpp:70
ndn
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-strategy-choice-helper.hpp:34
ns3::ndn::RttEstimator::ResetMultiplier
virtual void ResetMultiplier()
Resets the estimation multiplier to 1.
Definition: ndn-rtt-estimator.cpp:237