Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 21 | #include "ndn-consumer.hpp" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 22 | #include "ns3/ptr.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 23 | #include "ns3/log.h" |
| 24 | #include "ns3/simulator.h" |
| 25 | #include "ns3/packet.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 26 | #include "ns3/callback.h" |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 27 | #include "ns3/string.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 28 | #include "ns3/boolean.h" |
| 29 | #include "ns3/uinteger.h" |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 30 | #include "ns3/integer.h" |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 31 | #include "ns3/double.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 33 | #include "ns3/ndn-app-face.hpp" |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 34 | #include "ns3/ndnSIM/utils/ndn-fw-hop-count-tag.hpp" |
| 35 | #include "ns3/ndnSIM/utils/ndn-rtt-mean-deviation.hpp" |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 37 | #include <boost/ref.hpp> |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 38 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 39 | NS_LOG_COMPONENT_DEFINE("ndn.Consumer"); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 40 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 41 | namespace ns3 { |
| 42 | namespace ndn { |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 43 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 44 | NS_OBJECT_ENSURE_REGISTERED(Consumer); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 45 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 46 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 47 | Consumer::GetTypeId(void) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 48 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 49 | static TypeId tid = |
| 50 | TypeId("ns3::ndn::Consumer") |
| 51 | .SetGroupName("Ndn") |
| 52 | .SetParent<App>() |
| 53 | .AddAttribute("StartSeq", "Initial sequence number", IntegerValue(0), |
| 54 | MakeIntegerAccessor(&Consumer::m_seq), MakeIntegerChecker<int32_t>()) |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 55 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 56 | .AddAttribute("Prefix", "Name of the Interest", StringValue("/"), |
| 57 | MakeNameAccessor(&Consumer::m_interestName), MakeNameChecker()) |
| 58 | .AddAttribute("LifeTime", "LifeTime for interest packet", StringValue("2s"), |
| 59 | MakeTimeAccessor(&Consumer::m_interestLifeTime), MakeTimeChecker()) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 60 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 61 | .AddAttribute("RetxTimer", |
| 62 | "Timeout defining how frequent retransmission timeouts should be checked", |
| 63 | StringValue("50ms"), |
| 64 | MakeTimeAccessor(&Consumer::GetRetxTimer, &Consumer::SetRetxTimer), |
| 65 | MakeTimeChecker()) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 66 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 67 | .AddTraceSource("LastRetransmittedInterestDataDelay", |
| 68 | "Delay between last retransmitted Interest and received Data", |
| 69 | MakeTraceSourceAccessor(&Consumer::m_lastRetransmittedInterestDataDelay)) |
Alexander Afanasyev | edf24d9 | 2013-01-18 13:35:06 -0800 | [diff] [blame] | 70 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 71 | .AddTraceSource("FirstInterestDataDelay", |
| 72 | "Delay between first transmitted Interest and received Data", |
| 73 | MakeTraceSourceAccessor(&Consumer::m_firstInterestDataDelay)); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 74 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 75 | return tid; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 76 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 78 | Consumer::Consumer() |
| 79 | : m_rand(0, std::numeric_limits<uint32_t>::max()) |
| 80 | , m_seq(0) |
| 81 | , m_seqMax(0) // don't request anything |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 82 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 83 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 84 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 85 | m_rtt = CreateObject<RttMeanDeviation>(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 86 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 87 | |
| 88 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 89 | Consumer::SetRetxTimer(Time retxTimer) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 90 | { |
| 91 | m_retxTimer = retxTimer; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | if (m_retxEvent.IsRunning()) { |
| 93 | // m_retxEvent.Cancel (); // cancel any scheduled cleanup events |
| 94 | Simulator::Remove(m_retxEvent); // slower, but better for memory |
| 95 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 96 | |
| 97 | // schedule even with new timeout |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 98 | m_retxEvent = Simulator::Schedule(m_retxTimer, &Consumer::CheckRetxTimeout, this); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | Time |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 102 | Consumer::GetRetxTimer() const |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 103 | { |
| 104 | return m_retxTimer; |
| 105 | } |
| 106 | |
| 107 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 108 | Consumer::CheckRetxTimeout() |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 109 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 110 | Time now = Simulator::Now(); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 111 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 112 | Time rto = m_rtt->RetransmitTimeout(); |
Alexander Afanasyev | 8a23752 | 2013-02-01 13:33:38 -0800 | [diff] [blame] | 113 | // NS_LOG_DEBUG ("Current RTO: " << rto.ToDouble (Time::S) << "s"); |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 115 | while (!m_seqTimeouts.empty()) { |
| 116 | SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry = |
| 117 | m_seqTimeouts.get<i_timestamp>().begin(); |
| 118 | if (entry->time + rto <= now) // timeout expired? |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 119 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 120 | uint32_t seqNo = entry->seq; |
| 121 | m_seqTimeouts.get<i_timestamp>().erase(entry); |
| 122 | OnTimeout(seqNo); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 123 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 124 | else |
| 125 | break; // nothing else to do. All later packets need not be retransmitted |
| 126 | } |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 127 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 128 | m_retxEvent = Simulator::Schedule(m_retxTimer, &Consumer::CheckRetxTimeout, this); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 129 | } |
| 130 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 131 | // Application Methods |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 132 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 133 | Consumer::StartApplication() // Called at time specified by Start |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 134 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 135 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 136 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 137 | // do base stuff |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 138 | App::StartApplication(); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 139 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 140 | ScheduleNextPacket(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 141 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 142 | |
| 143 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 144 | Consumer::StopApplication() // Called at time specified by Stop |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 145 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 146 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 147 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 148 | // cancel periodic packet generation |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 149 | Simulator::Cancel(m_sendEvent); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 150 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 151 | // cleanup base stuff |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 152 | App::StopApplication(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 153 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 154 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 155 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 156 | Consumer::SendPacket() |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 157 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 158 | if (!m_active) |
| 159 | return; |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 160 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 161 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 162 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 163 | uint32_t seq = std::numeric_limits<uint32_t>::max(); // invalid |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 164 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 165 | while (m_retxSeqs.size()) { |
| 166 | seq = *m_retxSeqs.begin(); |
| 167 | m_retxSeqs.erase(m_retxSeqs.begin()); |
| 168 | break; |
| 169 | } |
| 170 | |
| 171 | if (seq == std::numeric_limits<uint32_t>::max()) { |
| 172 | if (m_seqMax != std::numeric_limits<uint32_t>::max()) { |
| 173 | if (m_seq >= m_seqMax) { |
| 174 | return; // we are totally done |
| 175 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 176 | } |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 177 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 178 | seq = m_seq++; |
| 179 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 180 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 181 | // |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 182 | shared_ptr<Name> nameWithSequence = make_shared<Name>(m_interestName); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 183 | nameWithSequence->appendSeqNum(seq); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 184 | // |
| 185 | |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 186 | shared_ptr<Interest> interest = make_shared<Interest>(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 187 | interest->SetNonce(m_rand.GetValue()); |
| 188 | interest->SetName(nameWithSequence); |
| 189 | interest->SetInterestLifetime(m_interestLifeTime); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 190 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 191 | // NS_LOG_INFO ("Requesting Interest: \n" << *interest); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 192 | NS_LOG_INFO("> Interest for " << seq); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 193 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 194 | WillSendOutInterest(seq); |
Alexander Afanasyev | e1aa9b9 | 2012-10-11 10:40:02 -0700 | [diff] [blame] | 195 | |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 196 | FwHopCountTag hopCountTag; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 197 | interest->GetPayload()->AddPacketTag(hopCountTag); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 198 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 199 | m_transmittedInterests(interest, this, m_face); |
| 200 | m_face->ReceiveInterest(interest); |
Alexander Afanasyev | e1aa9b9 | 2012-10-11 10:40:02 -0700 | [diff] [blame] | 201 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 202 | ScheduleNextPacket(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 203 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 204 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 205 | /////////////////////////////////////////////////// |
| 206 | // Process incoming packets // |
| 207 | /////////////////////////////////////////////////// |
| 208 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 209 | void |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 210 | Consumer::OnData(shared_ptr<const Data> data) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 211 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 212 | if (!m_active) |
| 213 | return; |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 214 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 215 | App::OnData(data); // tracing inside |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 216 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 217 | NS_LOG_FUNCTION(this << data); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 218 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 219 | // NS_LOG_INFO ("Received content object: " << boost::cref(*data)); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 220 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 221 | uint32_t seq = data->GetName().get(-1).toSeqNum(); |
| 222 | NS_LOG_INFO("< DATA for " << seq); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 223 | |
Alexander Afanasyev | 1a0fff6 | 2013-01-19 14:29:51 -0800 | [diff] [blame] | 224 | int hopCount = -1; |
| 225 | FwHopCountTag hopCountTag; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 226 | if (data->GetPayload()->PeekPacketTag(hopCountTag)) { |
| 227 | hopCount = hopCountTag.Get(); |
| 228 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 229 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 230 | SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find(seq); |
| 231 | if (entry != m_seqLastDelay.end()) { |
| 232 | m_lastRetransmittedInterestDataDelay(this, seq, Simulator::Now() - entry->time, hopCount); |
| 233 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 234 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 235 | entry = m_seqFullDelay.find(seq); |
| 236 | if (entry != m_seqFullDelay.end()) { |
| 237 | m_firstInterestDataDelay(this, seq, Simulator::Now() - entry->time, m_seqRetxCounts[seq], |
| 238 | hopCount); |
| 239 | } |
Alexander Afanasyev | 400aae1 | 2013-01-19 13:27:52 -0800 | [diff] [blame] | 240 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 241 | m_seqRetxCounts.erase(seq); |
| 242 | m_seqFullDelay.erase(seq); |
| 243 | m_seqLastDelay.erase(seq); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 244 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 245 | m_seqTimeouts.erase(seq); |
| 246 | m_retxSeqs.erase(seq); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 247 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 248 | m_rtt->AckSeq(SequenceNumber32(seq)); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 252 | Consumer::OnNack(shared_ptr<const Interest> interest) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 253 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 254 | if (!m_active) |
| 255 | return; |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 256 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 257 | App::OnNack(interest); // tracing inside |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 258 | |
Alexander Afanasyev | e1b2a2d | 2012-11-16 11:53:42 -0800 | [diff] [blame] | 259 | // NS_LOG_DEBUG ("Nack type: " << interest->GetNack ()); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 260 | |
Alexander Afanasyev | e1b2a2d | 2012-11-16 11:53:42 -0800 | [diff] [blame] | 261 | // NS_LOG_FUNCTION (interest->GetName ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 262 | |
| 263 | // NS_LOG_INFO ("Received NACK: " << boost::cref(*interest)); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 264 | uint32_t seq = interest->GetName().get(-1).toSeqNum(); |
| 265 | NS_LOG_INFO("< NACK for " << seq); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 266 | // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << "NACK for " << seq << "\n"; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 267 | |
| 268 | // put in the queue of interests to be retransmitted |
Alexander Afanasyev | e1b2a2d | 2012-11-16 11:53:42 -0800 | [diff] [blame] | 269 | // NS_LOG_INFO ("Before: " << m_retxSeqs.size ()); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 270 | m_retxSeqs.insert(seq); |
Alexander Afanasyev | e1b2a2d | 2012-11-16 11:53:42 -0800 | [diff] [blame] | 271 | // NS_LOG_INFO ("After: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 272 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 273 | m_seqTimeouts.erase(seq); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 274 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 275 | m_rtt->IncreaseMultiplier(); // Double the next RTO ?? |
| 276 | ScheduleNextPacket(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 277 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 278 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 279 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 280 | Consumer::OnTimeout(uint32_t sequenceNumber) |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 281 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 282 | NS_LOG_FUNCTION(sequenceNumber); |
| 283 | // std::cout << Simulator::Now () << ", TO: " << sequenceNumber << ", current RTO: " << |
| 284 | // m_rtt->RetransmitTimeout ().ToDouble (Time::S) << "s\n"; |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 285 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 286 | m_rtt->IncreaseMultiplier(); // Double the next RTO |
| 287 | m_rtt->SentSeq(SequenceNumber32(sequenceNumber), |
| 288 | 1); // make sure to disable RTT calculation for this sample |
| 289 | m_retxSeqs.insert(sequenceNumber); |
| 290 | ScheduleNextPacket(); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 293 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 294 | Consumer::WillSendOutInterest(uint32_t sequenceNumber) |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 295 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 296 | NS_LOG_DEBUG("Trying to add " << sequenceNumber << " with " << Simulator::Now() << ". already " |
| 297 | << m_seqTimeouts.size() << " items"); |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 298 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 299 | m_seqTimeouts.insert(SeqTimeout(sequenceNumber, Simulator::Now())); |
| 300 | m_seqFullDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now())); |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 301 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 302 | m_seqLastDelay.erase(sequenceNumber); |
| 303 | m_seqLastDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now())); |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 304 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 305 | m_seqRetxCounts[sequenceNumber]++; |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 306 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 307 | m_rtt->SentSeq(SequenceNumber32(sequenceNumber), 1); |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 310 | } // namespace ndn |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 311 | } // namespace ns3 |