blob: 619e2f199abc1caff43abff0721cb464910ce45b [file] [log] [blame]
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 University of California, Los Angeles
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: Ilya Moiseenko <iliamo@cs.ucla.edu>
19 */
20
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070021#include "ndn-consumer.h"
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070022#include "ns3/ptr.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080023#include "ns3/log.h"
24#include "ns3/simulator.h"
25#include "ns3/packet.h"
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -070026#include "ns3/callback.h"
Alexander Afanasyeva46844b2011-11-21 19:13:26 -080027#include "ns3/string.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080028#include "ns3/boolean.h"
29#include "ns3/uinteger.h"
Alexander Afanasyeva89bc102013-07-16 10:17:31 -070030#include "ns3/integer.h"
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080031#include "ns3/double.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080032
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070033#include "ns3/ndn-app-face.h"
Alexander Afanasyevbd9c18e2012-11-19 15:23:41 -080034#include "ns3/ndn-interest.h"
35#include "ns3/ndn-content-object.h"
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -080036#include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.h"
Alexander Afanasyevd9a7f192013-03-07 13:58:14 -080037#include "ns3/ndnSIM/utils/ndn-rtt-mean-deviation.h"
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070038
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080039#include <boost/ref.hpp>
Alexander Afanasyev781ea812011-12-15 22:42:09 -080040
Alexander Afanasyev3661e232012-01-20 17:36:15 -080041#include "ns3/names.h"
42
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070043NS_LOG_COMPONENT_DEFINE ("ndn.Consumer");
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070044
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070045namespace ns3 {
46namespace ndn {
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080047
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070048NS_OBJECT_ENSURE_REGISTERED (Consumer);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080049
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070050TypeId
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070051Consumer::GetTypeId (void)
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070052{
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070053 static TypeId tid = TypeId ("ns3::ndn::Consumer")
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070054 .SetGroupName ("Ndn")
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070055 .SetParent<App> ()
Alexander Afanasyev781ea812011-12-15 22:42:09 -080056 .AddAttribute ("StartSeq", "Initial sequence number",
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080057 IntegerValue (0),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070058 MakeIntegerAccessor(&Consumer::m_seq),
Alexander Afanasyev781ea812011-12-15 22:42:09 -080059 MakeIntegerChecker<int32_t>())
Alexander Afanasyev011b8592011-12-21 14:45:27 -080060
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070061 .AddAttribute ("Prefix","Name of the Interest",
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080062 StringValue ("/"),
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -070063 MakeNameAccessor (&Consumer::m_interestName),
64 MakeNameChecker ())
Ilya Moiseenko956d0542012-01-02 15:26:40 -080065 .AddAttribute ("LifeTime", "LifeTime for interest packet",
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080066 StringValue ("2s"),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070067 MakeTimeAccessor (&Consumer::m_interestLifeTime),
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080068 MakeTimeChecker ())
Alexander Afanasyev781ea812011-12-15 22:42:09 -080069
Alexander Afanasyev781ea812011-12-15 22:42:09 -080070 .AddAttribute ("RetxTimer",
71 "Timeout defining how frequent retransmission timeouts should be checked",
Alexander Afanasyev3d0c2e02012-01-22 18:50:05 -080072 StringValue ("50ms"),
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070073 MakeTimeAccessor (&Consumer::GetRetxTimer, &Consumer::SetRetxTimer),
Alexander Afanasyev781ea812011-12-15 22:42:09 -080074 MakeTimeChecker ())
75
Alexander Afanasyevedf24d92013-01-18 13:35:06 -080076 .AddTraceSource ("LastRetransmittedInterestDataDelay", "Delay between last retransmitted Interest and received Data",
77 MakeTraceSourceAccessor (&Consumer::m_lastRetransmittedInterestDataDelay))
78
79 .AddTraceSource ("FirstInterestDataDelay", "Delay between first transmitted Interest and received Data",
80 MakeTraceSourceAccessor (&Consumer::m_firstInterestDataDelay))
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080081 ;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070082
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080083 return tid;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070084}
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -080085
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070086Consumer::Consumer ()
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080087 : m_rand (0, std::numeric_limits<uint32_t>::max ())
88 , m_seq (0)
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -080089 , m_seqMax (0) // don't request anything
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070090{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080091 NS_LOG_FUNCTION_NOARGS ();
Alexander Afanasyev011b8592011-12-21 14:45:27 -080092
Alexander Afanasyev94cebd02012-01-16 12:22:34 -080093 m_rtt = CreateObject<RttMeanDeviation> ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070094}
Alexander Afanasyev781ea812011-12-15 22:42:09 -080095
96void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -070097Consumer::SetRetxTimer (Time retxTimer)
Alexander Afanasyev781ea812011-12-15 22:42:09 -080098{
99 m_retxTimer = retxTimer;
100 if (m_retxEvent.IsRunning ())
Alexander Afanasyevb18ae022012-09-03 21:46:36 -0700101 {
102 // m_retxEvent.Cancel (); // cancel any scheduled cleanup events
103 Simulator::Remove (m_retxEvent); // slower, but better for memory
104 }
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800105
106 // schedule even with new timeout
107 m_retxEvent = Simulator::Schedule (m_retxTimer,
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800108 &Consumer::CheckRetxTimeout, this);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800109}
110
111Time
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700112Consumer::GetRetxTimer () const
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800113{
114 return m_retxTimer;
115}
116
117void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700118Consumer::CheckRetxTimeout ()
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800119{
120 Time now = Simulator::Now ();
121
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800122 Time rto = m_rtt->RetransmitTimeout ();
Alexander Afanasyev8a237522013-02-01 13:33:38 -0800123 // NS_LOG_DEBUG ("Current RTO: " << rto.ToDouble (Time::S) << "s");
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800124
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800125 while (!m_seqTimeouts.empty ())
126 {
127 SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry =
128 m_seqTimeouts.get<i_timestamp> ().begin ();
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800129 if (entry->time + rto <= now) // timeout expired?
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800130 {
Alexander Afanasyeve0e5bd12012-01-21 14:30:52 -0800131 uint32_t seqNo = entry->seq;
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800132 m_seqTimeouts.get<i_timestamp> ().erase (entry);
Alexander Afanasyeve0e5bd12012-01-21 14:30:52 -0800133 OnTimeout (seqNo);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800134 }
135 else
136 break; // nothing else to do. All later packets need not be retransmitted
137 }
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800138
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800139 m_retxEvent = Simulator::Schedule (m_retxTimer,
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800140 &Consumer::CheckRetxTimeout, this);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800141}
142
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700143// Application Methods
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800144void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700145Consumer::StartApplication () // Called at time specified by Start
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700146{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800147 NS_LOG_FUNCTION_NOARGS ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700148
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800149 // do base stuff
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700150 App::StartApplication ();
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800151
152 ScheduleNextPacket ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700153}
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800154
155void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700156Consumer::StopApplication () // Called at time specified by Stop
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700157{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800158 NS_LOG_FUNCTION_NOARGS ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700159
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800160 // cancel periodic packet generation
161 Simulator::Cancel (m_sendEvent);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700162
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800163 // cleanup base stuff
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700164 App::StopApplication ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700165}
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800166
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700167void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700168Consumer::SendPacket ()
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700169{
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800170 if (!m_active) return;
171
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800172 NS_LOG_FUNCTION_NOARGS ();
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800173
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800174 uint32_t seq=std::numeric_limits<uint32_t>::max (); //invalid
175
176 while (m_retxSeqs.size ())
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800177 {
178 seq = *m_retxSeqs.begin ();
179 m_retxSeqs.erase (m_retxSeqs.begin ());
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800180 break;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800181 }
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800182
183 if (seq == std::numeric_limits<uint32_t>::max ())
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800184 {
Alexander Afanasyev812f7ab2012-01-24 11:08:04 -0800185 if (m_seqMax != std::numeric_limits<uint32_t>::max ())
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800186 {
187 if (m_seq >= m_seqMax)
188 {
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800189 return; // we are totally done
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800190 }
191 }
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800192
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800193 seq = m_seq++;
194 }
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800195
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800196 //
Alexander Afanasyevcfdc14f2013-03-15 14:38:44 -0700197 Ptr<Name> nameWithSequence = Create<Name> (m_interestName);
Alexander Afanasyev92136012013-07-16 20:36:30 -0700198 nameWithSequence->appendSeqNum (seq);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800199 //
200
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700201 Ptr<Interest> interest = Create<Interest> ();
202 interest->SetNonce (m_rand.GetValue ());
203 interest->SetName (nameWithSequence);
204 interest->SetInterestLifetime (m_interestLifeTime);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800205
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700206 // NS_LOG_INFO ("Requesting Interest: \n" << *interest);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800207 NS_LOG_INFO ("> Interest for " << seq);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700208
Alexander Afanasyev79b2fb32013-04-12 11:24:55 -0700209 WillSendOutInterest (seq);
Alexander Afanasyeve1aa9b92012-10-11 10:40:02 -0700210
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800211 FwHopCountTag hopCountTag;
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700212 interest->GetPayload ()->AddPacketTag (hopCountTag);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800213
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700214 m_transmittedInterests (interest, this, m_face);
215 m_face->ReceiveInterest (interest);
Alexander Afanasyeve1aa9b92012-10-11 10:40:02 -0700216
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800217 ScheduleNextPacket ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700218}
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700219
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800220///////////////////////////////////////////////////
221// Process incoming packets //
222///////////////////////////////////////////////////
223
224
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700225void
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700226Consumer::OnContentObject (Ptr<const ContentObject> data)
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700227{
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800228 if (!m_active) return;
229
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700230 App::OnContentObject (data); // tracing inside
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800231
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700232 NS_LOG_FUNCTION (this << data);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800233
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700234 // NS_LOG_INFO ("Received content object: " << boost::cref(*data));
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800235
Alexander Afanasyev92136012013-07-16 20:36:30 -0700236 uint32_t seq = data->GetName ().get (-1).toSeqNum ();
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800237 NS_LOG_INFO ("< DATA for " << seq);
238
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800239 int hopCount = -1;
240 FwHopCountTag hopCountTag;
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700241 if (data->GetPayload ()->PeekPacketTag (hopCountTag))
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800242 {
243 hopCount = hopCountTag.Get ();
244 }
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800245
Alexander Afanasyev400aae12013-01-19 13:27:52 -0800246 SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find (seq);
247 if (entry != m_seqLastDelay.end ())
Alexander Afanasyevedf24d92013-01-18 13:35:06 -0800248 {
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800249 m_lastRetransmittedInterestDataDelay (this, seq, Simulator::Now () - entry->time, hopCount);
Alexander Afanasyevedf24d92013-01-18 13:35:06 -0800250 }
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800251
Alexander Afanasyev400aae12013-01-19 13:27:52 -0800252 entry = m_seqFullDelay.find (seq);
253 if (entry != m_seqFullDelay.end ())
Alexander Afanasyevedf24d92013-01-18 13:35:06 -0800254 {
Alexander Afanasyev1a0fff62013-01-19 14:29:51 -0800255 m_firstInterestDataDelay (this, seq, Simulator::Now () - entry->time, m_seqRetxCounts[seq], hopCount);
Alexander Afanasyevedf24d92013-01-18 13:35:06 -0800256 }
Alexander Afanasyev400aae12013-01-19 13:27:52 -0800257
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800258 m_seqRetxCounts.erase (seq);
Alexander Afanasyev400aae12013-01-19 13:27:52 -0800259 m_seqFullDelay.erase (seq);
260 m_seqLastDelay.erase (seq);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800261
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800262 m_seqTimeouts.erase (seq);
263 m_retxSeqs.erase (seq);
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800264
265 m_rtt->AckSeq (SequenceNumber32 (seq));
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800266}
267
268void
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700269Consumer::OnNack (Ptr<const Interest> interest)
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800270{
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800271 if (!m_active) return;
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800272
Alexander Afanasyevfaa01f92013-07-10 18:34:31 -0700273 App::OnNack (interest); // tracing inside
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800274
Alexander Afanasyeve1b2a2d2012-11-16 11:53:42 -0800275 // NS_LOG_DEBUG ("Nack type: " << interest->GetNack ());
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800276
Alexander Afanasyeve1b2a2d2012-11-16 11:53:42 -0800277 // NS_LOG_FUNCTION (interest->GetName ());
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800278
279 // NS_LOG_INFO ("Received NACK: " << boost::cref(*interest));
Alexander Afanasyev92136012013-07-16 20:36:30 -0700280 uint32_t seq = interest->GetName ().get (-1).toSeqNum ();
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800281 NS_LOG_INFO ("< NACK for " << seq);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800282 // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << "NACK for " << seq << "\n";
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800283
284 // put in the queue of interests to be retransmitted
Alexander Afanasyeve1b2a2d2012-11-16 11:53:42 -0800285 // NS_LOG_INFO ("Before: " << m_retxSeqs.size ());
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800286 m_retxSeqs.insert (seq);
Alexander Afanasyeve1b2a2d2012-11-16 11:53:42 -0800287 // NS_LOG_INFO ("After: " << m_retxSeqs.size ());
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800288
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800289 m_seqTimeouts.erase (seq);
290
Alexander Afanasyev92d5be12012-08-13 18:56:52 -0700291 m_rtt->IncreaseMultiplier (); // Double the next RTO ??
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800292 ScheduleNextPacket ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700293}
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700294
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800295void
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700296Consumer::OnTimeout (uint32_t sequenceNumber)
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800297{
Alexander Afanasyev92d5be12012-08-13 18:56:52 -0700298 NS_LOG_FUNCTION (sequenceNumber);
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800299 // std::cout << Simulator::Now () << ", TO: " << sequenceNumber << ", current RTO: " << m_rtt->RetransmitTimeout ().ToDouble (Time::S) << "s\n";
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800300
Alexander Afanasyev92d5be12012-08-13 18:56:52 -0700301 m_rtt->IncreaseMultiplier (); // Double the next RTO
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800302 m_rtt->SentSeq (SequenceNumber32 (sequenceNumber), 1); // make sure to disable RTT calculation for this sample
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800303 m_retxSeqs.insert (sequenceNumber);
Alexander Afanasyev3a3ce1a2013-01-31 11:26:11 -0800304 ScheduleNextPacket ();
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800305}
306
Alexander Afanasyev79b2fb32013-04-12 11:24:55 -0700307void
308Consumer::WillSendOutInterest (uint32_t sequenceNumber)
309{
310 NS_LOG_DEBUG ("Trying to add " << sequenceNumber << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items");
311
312 m_seqTimeouts.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
313 m_seqFullDelay.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
314
315 m_seqLastDelay.erase (sequenceNumber);
316 m_seqLastDelay.insert (SeqTimeout (sequenceNumber, Simulator::Now ()));
317
318 m_seqRetxCounts[sequenceNumber] ++;
319
320 m_rtt->SentSeq (SequenceNumber32 (sequenceNumber), 1);
321}
322
323
Alexander Afanasyev2b4c9472012-08-09 15:00:38 -0700324} // namespace ndn
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800325} // namespace ns3