blob: 6d976fc18c408e86d344ff5fc239e7c39a1875eb [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 Afanasyevb3e4b852011-12-23 15:58:20 -080030#include "ns3/double.h"
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080031
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070032#include "ns3/ndn.h"
33#include "ns3/ndn-app-face.h"
34#include "ns3/ndn-interest-header.h"
35#include "ns3/ndn-content-object-header.h"
Alexander Afanasyevde7601a2012-05-31 12:14:54 -070036// #include "ns3/weights-path-stretch-tag.h"
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070037
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080038#include <boost/ref.hpp>
Alexander Afanasyev781ea812011-12-15 22:42:09 -080039#include <boost/lexical_cast.hpp>
40#include <boost/lambda/lambda.hpp>
41#include <boost/lambda/bind.hpp>
42
Alexander Afanasyev3661e232012-01-20 17:36:15 -080043#include "ns3/names.h"
44
Alexander Afanasyev781ea812011-12-15 22:42:09 -080045namespace ll = boost::lambda;
Alexander Afanasyev19426ef2011-11-23 20:55:28 -080046
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070047NS_LOG_COMPONENT_DEFINE ("NdnConsumer");
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070048
49namespace ns3
50{
51
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070052NS_OBJECT_ENSURE_REGISTERED (NdnConsumer);
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070053
54TypeId
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070055NdnConsumer::GetTypeId (void)
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070056{
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070057 static TypeId tid = TypeId ("ns3::NdnConsumer")
58 .SetGroupName ("Ndn")
59 .SetParent<NdnApp> ()
Alexander Afanasyev781ea812011-12-15 22:42:09 -080060 .AddAttribute ("StartSeq", "Initial sequence number",
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -080061 IntegerValue (0),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070062 MakeIntegerAccessor(&NdnConsumer::m_seq),
Alexander Afanasyev781ea812011-12-15 22:42:09 -080063 MakeIntegerChecker<int32_t>())
Alexander Afanasyev011b8592011-12-21 14:45:27 -080064
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070065 .AddAttribute ("Prefix","NdnName of the Interest",
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080066 StringValue ("/"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070067 MakeNdnNameComponentsAccessor (&NdnConsumer::m_interestName),
68 MakeNdnNameComponentsChecker ())
Ilya Moiseenko956d0542012-01-02 15:26:40 -080069 .AddAttribute ("LifeTime", "LifeTime for interest packet",
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080070 StringValue ("2s"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070071 MakeTimeAccessor (&NdnConsumer::m_interestLifeTime),
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080072 MakeTimeChecker ())
73 .AddAttribute ("MinSuffixComponents", "MinSuffixComponents",
74 IntegerValue(-1),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070075 MakeIntegerAccessor(&NdnConsumer::m_minSuffixComponents),
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080076 MakeIntegerChecker<int32_t>())
77 .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents",
78 IntegerValue(-1),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070079 MakeIntegerAccessor(&NdnConsumer::m_maxSuffixComponents),
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080080 MakeIntegerChecker<int32_t>())
81 .AddAttribute ("ChildSelector", "ChildSelector",
82 BooleanValue(false),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070083 MakeBooleanAccessor(&NdnConsumer::m_childSelector),
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080084 MakeBooleanChecker())
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070085 .AddAttribute ("Exclude", "only simple name matching is supported (use NdnNameComponents)",
86 NdnNameComponentsValue (),
87 MakeNdnNameComponentsAccessor (&NdnConsumer::m_exclude),
88 MakeNdnNameComponentsChecker ())
Alexander Afanasyev781ea812011-12-15 22:42:09 -080089
Alexander Afanasyev781ea812011-12-15 22:42:09 -080090 .AddAttribute ("RetxTimer",
91 "Timeout defining how frequent retransmission timeouts should be checked",
Alexander Afanasyev3d0c2e02012-01-22 18:50:05 -080092 StringValue ("50ms"),
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070093 MakeTimeAccessor (&NdnConsumer::GetRetxTimer, &NdnConsumer::SetRetxTimer),
Alexander Afanasyev781ea812011-12-15 22:42:09 -080094 MakeTimeChecker ())
95
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -080096 .AddTraceSource ("PathWeightsTrace", "PathWeightsTrace",
Alexander Afanasyev4aac5572012-08-09 10:49:55 -070097 MakeTraceSourceAccessor (&NdnConsumer::m_pathWeightsTrace))
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -080098 ;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -070099
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800100 return tid;
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700101}
102
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700103NdnConsumer::NdnConsumer ()
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800104 : m_rand (0, std::numeric_limits<uint32_t>::max ())
105 , m_seq (0)
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800106 , m_seqMax (0) // don't request anything
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700107{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800108 NS_LOG_FUNCTION_NOARGS ();
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800109
Alexander Afanasyev94cebd02012-01-16 12:22:34 -0800110 m_rtt = CreateObject<RttMeanDeviation> ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700111}
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800112
113void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700114NdnConsumer::SetRetxTimer (Time retxTimer)
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800115{
116 m_retxTimer = retxTimer;
117 if (m_retxEvent.IsRunning ())
118 m_retxEvent.Cancel (); // cancel any scheduled cleanup events
119
120 // schedule even with new timeout
121 m_retxEvent = Simulator::Schedule (m_retxTimer,
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700122 &NdnConsumer::CheckRetxTimeout, this);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800123}
124
125Time
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700126NdnConsumer::GetRetxTimer () const
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800127{
128 return m_retxTimer;
129}
130
131void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700132NdnConsumer::CheckRetxTimeout ()
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800133{
134 Time now = Simulator::Now ();
135
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800136 Time rto = m_rtt->RetransmitTimeout ();
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800137
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800138 while (!m_seqTimeouts.empty ())
139 {
140 SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry =
141 m_seqTimeouts.get<i_timestamp> ().begin ();
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800142 if (entry->time + rto <= now) // timeout expired?
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800143 {
Alexander Afanasyeve0e5bd12012-01-21 14:30:52 -0800144 uint32_t seqNo = entry->seq;
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800145 m_seqTimeouts.get<i_timestamp> ().erase (entry);
Alexander Afanasyeve0e5bd12012-01-21 14:30:52 -0800146 OnTimeout (seqNo);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800147 }
148 else
149 break; // nothing else to do. All later packets need not be retransmitted
150 }
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800151
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800152 m_retxEvent = Simulator::Schedule (m_retxTimer,
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700153 &NdnConsumer::CheckRetxTimeout, this);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800154}
155
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700156// Application Methods
157void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700158NdnConsumer::StartApplication () // Called at time specified by Start
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700159{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800160 NS_LOG_FUNCTION_NOARGS ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700161
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800162 // do base stuff
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700163 NdnApp::StartApplication ();
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800164
165 ScheduleNextPacket ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700166}
167
168void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700169NdnConsumer::StopApplication () // Called at time specified by Stop
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700170{
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800171 NS_LOG_FUNCTION_NOARGS ();
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700172
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800173 // cancel periodic packet generation
174 Simulator::Cancel (m_sendEvent);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700175
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800176 // cleanup base stuff
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700177 NdnApp::StopApplication ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700178}
179
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700180void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700181NdnConsumer::SendPacket ()
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700182{
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800183 if (!m_active) return;
184
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800185 NS_LOG_FUNCTION_NOARGS ();
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800186
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800187 uint32_t seq=std::numeric_limits<uint32_t>::max (); //invalid
188
Alexander Afanasyev1180b042012-01-25 19:26:13 -0800189 // std::cout << Simulator::Now ().ToDouble (Time::S) << "s max -> " << m_seqMax << "\n";
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800190
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800191 while (m_retxSeqs.size ())
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800192 {
193 seq = *m_retxSeqs.begin ();
194 m_retxSeqs.erase (m_retxSeqs.begin ());
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800195
196 // NS_ASSERT (m_seqLifetimes.find (seq) != m_seqLifetimes.end ());
197 // if (m_seqLifetimes.find (seq)->time <= Simulator::Now ())
198 // {
199
200 // NS_LOG_DEBUG ("Expire " << seq);
201 // m_seqLifetimes.erase (seq); // lifetime expired. Trying to find another unexpired sequence number
202 // continue;
203 // }
204 break;
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800205 }
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800206
207 if (seq == std::numeric_limits<uint32_t>::max ())
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800208 {
Alexander Afanasyev812f7ab2012-01-24 11:08:04 -0800209 if (m_seqMax != std::numeric_limits<uint32_t>::max ())
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800210 {
211 if (m_seq >= m_seqMax)
212 {
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800213 return; // we are totally done
Alexander Afanasyevb3e4b852011-12-23 15:58:20 -0800214 }
215 }
216
217 seq = m_seq++;
218 }
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800219
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800220 // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << seq << "\n";
Ilya Moiseenko0605d262011-10-28 13:00:07 -0700221
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800222 //
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700223 Ptr<NdnNameComponents> nameWithSequence = Create<NdnNameComponents> (m_interestName);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800224 (*nameWithSequence) (seq);
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800225 //
226
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700227 NdnInterestHeader interestHeader;
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800228 interestHeader.SetNonce (m_rand.GetValue ());
229 interestHeader.SetName (nameWithSequence);
230 interestHeader.SetInterestLifetime (m_interestLifeTime);
231 interestHeader.SetChildSelector (m_childSelector);
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800232 if (m_exclude.size ()>0)
233 {
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700234 interestHeader.SetExclude (Create<NdnNameComponents> (m_exclude));
Alexander Afanasyevc39f0b42011-11-28 12:51:12 -0800235 }
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800236 interestHeader.SetMaxSuffixComponents (m_maxSuffixComponents);
237 interestHeader.SetMinSuffixComponents (m_minSuffixComponents);
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700238
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800239 // NS_LOG_INFO ("Requesting Interest: \n" << interestHeader);
240 NS_LOG_INFO ("> Interest for " << seq);
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700241
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800242 Ptr<Packet> packet = Create<Packet> ();
243 packet->AddHeader (interestHeader);
Alexander Afanasyev59e67712012-02-07 11:49:34 -0800244 NS_LOG_DEBUG ("Interest packet size: " << packet->GetSize ());
Alexander Afanasyevd02a5d62011-11-21 11:01:51 -0800245
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800246 m_protocolHandler (packet);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800247
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800248 NS_LOG_DEBUG ("Trying to add " << seq << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items");
249
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800250 m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ()));
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800251 m_seqLifetimes.insert (SeqTimeout (seq, Simulator::Now () + m_interestLifeTime)); // only one insert will work. if entry exists, nothing will happen... nothing should happen
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800252 m_transmittedInterests (&interestHeader, this, m_face);
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800253
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800254 m_rtt->SentSeq (SequenceNumber32 (seq), 1);
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800255 ScheduleNextPacket ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700256}
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700257
Alexander Afanasyev011b8592011-12-21 14:45:27 -0800258///////////////////////////////////////////////////
259// Process incoming packets //
260///////////////////////////////////////////////////
261
262
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700263void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700264NdnConsumer::OnContentObject (const Ptr<const NdnContentObjectHeader> &contentObject,
Alexander Afanasyeve9c9d722012-01-19 16:59:30 -0800265 Ptr<Packet> payload)
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700266{
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800267 if (!m_active) return;
268
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700269 NdnApp::OnContentObject (contentObject, payload); // tracing inside
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800270
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800271 NS_LOG_FUNCTION (this << contentObject << payload);
272
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800273 // NS_LOG_INFO ("Received content object: " << boost::cref(*contentObject));
274
275 uint32_t seq = boost::lexical_cast<uint32_t> (contentObject->GetName ().GetComponents ().back ());
276 NS_LOG_INFO ("< DATA for " << seq);
277
Alexander Afanasyev8dcfa5d2012-01-05 14:22:25 -0700278 // SeqTimeoutsContainer::iterator entry = m_seqTimeouts.find (seq);
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800279
Alexander Afanasyev8f5a9bb2011-12-18 19:49:02 -0800280 // NS_ASSERT_MSG (entry != m_seqTimeouts.end (),
281 // "Comment out this assert, if it causes problems");
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800282
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800283 // if (entry != m_seqTimeouts.end ())
284 // m_seqTimeouts.erase (entry);
285
Alexander Afanasyev1ec705f2012-01-23 12:35:10 -0800286 m_seqLifetimes.erase (seq);
Alexander Afanasyev36d5c2a2012-01-02 19:09:19 -0800287 m_seqTimeouts.erase (seq);
288 m_retxSeqs.erase (seq);
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800289
290 m_rtt->AckSeq (SequenceNumber32 (seq));
Alexander Afanasyev6bff0df2012-01-19 17:51:52 -0800291
Alexander Afanasyevde7601a2012-05-31 12:14:54 -0700292 // Ptr<const WeightsPathStretchTag> tag = payload->RemovePacketTag<WeightsPathStretchTag> ();
293 // if (tag != 0)
294 // {
295 // // Notify trace about path weights vector (e.g., for path-stretch calculation)
296 // m_pathWeightsTrace (GetNode (), tag->GetSourceNode (), seq, tag->GetTotalWeight ());
297 // // if (Names::FindName (GetNode ()) == "36")// || Names::FindName (GetNode ()) == "40"|| Names::FindName (GetNode ()) == "5")
298 // // std::cout << Simulator::Now () << "\t" << boost::cref(*tag) << " = " << tag->GetTotalWeight () << "\n";
299 // }
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800300}
301
302void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700303NdnConsumer::OnNack (const Ptr<const NdnInterestHeader> &interest, Ptr<Packet> origPacket)
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800304{
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800305 if (!m_active) return;
306
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700307 NdnApp::OnNack (interest, origPacket); // tracing inside
Alexander Afanasyevbdc0d982011-12-16 01:15:26 -0800308
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800309 NS_LOG_DEBUG ("Nack type: " << interest->GetNack ());
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800310
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800311 NS_LOG_FUNCTION (this << interest);
312
313 // NS_LOG_INFO ("Received NACK: " << boost::cref(*interest));
314 uint32_t seq = boost::lexical_cast<uint32_t> (interest->GetName ().GetComponents ().back ());
315 NS_LOG_INFO ("< NACK for " << seq);
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800316 // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << "NACK for " << seq << "\n";
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800317
318 // put in the queue of interests to be retransmitted
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800319 NS_LOG_INFO ("Before: " << m_retxSeqs.size ());
Alexander Afanasyev781ea812011-12-15 22:42:09 -0800320 m_retxSeqs.insert (seq);
Alexander Afanasyev120bf312011-12-19 01:24:47 -0800321 NS_LOG_INFO ("After: " << m_retxSeqs.size ());
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800322
Alexander Afanasyev1180b042012-01-25 19:26:13 -0800323 // m_rtt->IncreaseMultiplier (); // Double the next RTO ??
Alexander Afanasyev3183b5a2011-12-23 20:48:20 -0800324 ScheduleNextPacket ();
Ilya Moiseenko8196d2e2011-08-29 13:03:22 -0700325}
Alexander Afanasyevc5a23e22011-09-07 00:37:36 -0700326
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800327void
Alexander Afanasyev4aac5572012-08-09 10:49:55 -0700328NdnConsumer::OnTimeout (uint32_t sequenceNumber)
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800329{
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800330 // std::cout << Simulator::Now () << ", TO: " << sequenceNumber << ", current RTO: " << m_rtt->RetransmitTimeout ().ToDouble (Time::S) << "s\n";
Alexander Afanasyevb7ad2322012-01-17 22:54:49 -0800331
Alexander Afanasyevb8f51392012-01-23 10:59:51 -0800332 // m_rtt->IncreaseMultiplier (); // Double the next RTO
Alexander Afanasyev8e0d2812012-01-19 22:38:14 -0800333 m_rtt->SentSeq (SequenceNumber32 (sequenceNumber), 1); // make sure to disable RTT calculation for this sample
Alexander Afanasyev4d66de52012-01-13 00:06:01 -0800334 m_retxSeqs.insert (sequenceNumber);
Alexander Afanasyev359bfb72012-01-09 18:42:50 -0800335 ScheduleNextPacket ();
336}
337
Alexander Afanasyev09c7deb2011-11-23 14:50:10 -0800338} // namespace ns3