Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2011-2015 Regents of the University of California. |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 5 | * This file is part of ndnSIM. See AUTHORS for complete list of ndnSIM authors and |
| 6 | * contributors. |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 7 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 8 | * ndnSIM is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 11 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 12 | * ndnSIM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 15 | * |
Alexander Afanasyev | 60a7b62 | 2014-12-20 17:04:07 -0800 | [diff] [blame] | 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * ndnSIM, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | **/ |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 19 | |
Alexander Afanasyev | 0c39537 | 2014-12-20 15:54:02 -0800 | [diff] [blame] | 20 | #include "ndn-consumer.hpp" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 21 | #include "ns3/ptr.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 22 | #include "ns3/log.h" |
| 23 | #include "ns3/simulator.h" |
| 24 | #include "ns3/packet.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 25 | #include "ns3/callback.h" |
Alexander Afanasyev | a46844b | 2011-11-21 19:13:26 -0800 | [diff] [blame] | 26 | #include "ns3/string.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 27 | #include "ns3/boolean.h" |
| 28 | #include "ns3/uinteger.h" |
Alexander Afanasyev | a89bc10 | 2013-07-16 10:17:31 -0700 | [diff] [blame] | 29 | #include "ns3/integer.h" |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 30 | #include "ns3/double.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 31 | |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 32 | #include "utils/ndn-ns3-packet-tag.hpp" |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 33 | #include "utils/ndn-rtt-mean-deviation.hpp" |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 34 | |
Spyridon Mastorakis | 73df9f5 | 2016-12-07 14:34:13 -0800 | [diff] [blame] | 35 | #include <ndn-cxx/lp/tags.hpp> |
| 36 | |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 37 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 38 | #include <boost/ref.hpp> |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 40 | NS_LOG_COMPONENT_DEFINE("ndn.Consumer"); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 42 | namespace ns3 { |
| 43 | namespace ndn { |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 45 | NS_OBJECT_ENSURE_REGISTERED(Consumer); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 46 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 47 | TypeId |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 48 | Consumer::GetTypeId(void) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 49 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 50 | static TypeId tid = |
| 51 | TypeId("ns3::ndn::Consumer") |
| 52 | .SetGroupName("Ndn") |
| 53 | .SetParent<App>() |
| 54 | .AddAttribute("StartSeq", "Initial sequence number", IntegerValue(0), |
| 55 | MakeIntegerAccessor(&Consumer::m_seq), MakeIntegerChecker<int32_t>()) |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 56 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 57 | .AddAttribute("Prefix", "Name of the Interest", StringValue("/"), |
| 58 | MakeNameAccessor(&Consumer::m_interestName), MakeNameChecker()) |
| 59 | .AddAttribute("LifeTime", "LifeTime for interest packet", StringValue("2s"), |
| 60 | MakeTimeAccessor(&Consumer::m_interestLifeTime), MakeTimeChecker()) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 61 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 62 | .AddAttribute("RetxTimer", |
| 63 | "Timeout defining how frequent retransmission timeouts should be checked", |
| 64 | StringValue("50ms"), |
| 65 | MakeTimeAccessor(&Consumer::GetRetxTimer, &Consumer::SetRetxTimer), |
| 66 | MakeTimeChecker()) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 67 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 68 | .AddTraceSource("LastRetransmittedInterestDataDelay", |
| 69 | "Delay between last retransmitted Interest and received Data", |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 70 | MakeTraceSourceAccessor(&Consumer::m_lastRetransmittedInterestDataDelay), |
| 71 | "ns3::ndn::Consumer::LastRetransmittedInterestDataDelayCallback") |
Alexander Afanasyev | edf24d9 | 2013-01-18 13:35:06 -0800 | [diff] [blame] | 72 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 73 | .AddTraceSource("FirstInterestDataDelay", |
| 74 | "Delay between first transmitted Interest and received Data", |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 75 | MakeTraceSourceAccessor(&Consumer::m_firstInterestDataDelay), |
| 76 | "ns3::ndn::Consumer::FirstInterestDataDelayCallback"); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 77 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 78 | return tid; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 79 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 80 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 81 | Consumer::Consumer() |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 82 | : m_rand(CreateObject<UniformRandomVariable>()) |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 83 | , m_seq(0) |
| 84 | , m_seqMax(0) // don't request anything |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 85 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 86 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 88 | m_rtt = CreateObject<RttMeanDeviation>(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 89 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 90 | |
| 91 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 92 | Consumer::SetRetxTimer(Time retxTimer) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 93 | { |
| 94 | m_retxTimer = retxTimer; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 95 | if (m_retxEvent.IsRunning()) { |
| 96 | // m_retxEvent.Cancel (); // cancel any scheduled cleanup events |
| 97 | Simulator::Remove(m_retxEvent); // slower, but better for memory |
| 98 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 99 | |
| 100 | // schedule even with new timeout |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 101 | m_retxEvent = Simulator::Schedule(m_retxTimer, &Consumer::CheckRetxTimeout, this); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | Time |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 105 | Consumer::GetRetxTimer() const |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 106 | { |
| 107 | return m_retxTimer; |
| 108 | } |
| 109 | |
| 110 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 111 | Consumer::CheckRetxTimeout() |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 112 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 113 | Time now = Simulator::Now(); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 114 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 115 | Time rto = m_rtt->RetransmitTimeout(); |
Alexander Afanasyev | 8a23752 | 2013-02-01 13:33:38 -0800 | [diff] [blame] | 116 | // NS_LOG_DEBUG ("Current RTO: " << rto.ToDouble (Time::S) << "s"); |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 117 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 118 | while (!m_seqTimeouts.empty()) { |
| 119 | SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry = |
| 120 | m_seqTimeouts.get<i_timestamp>().begin(); |
| 121 | if (entry->time + rto <= now) // timeout expired? |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 122 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 123 | uint32_t seqNo = entry->seq; |
| 124 | m_seqTimeouts.get<i_timestamp>().erase(entry); |
| 125 | OnTimeout(seqNo); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 126 | } |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 127 | else |
| 128 | break; // nothing else to do. All later packets need not be retransmitted |
| 129 | } |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 130 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 131 | m_retxEvent = Simulator::Schedule(m_retxTimer, &Consumer::CheckRetxTimeout, this); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 134 | // Application Methods |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 135 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 136 | Consumer::StartApplication() // Called at time specified by Start |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 137 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 138 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 139 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 140 | // do base stuff |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 141 | App::StartApplication(); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 142 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 143 | ScheduleNextPacket(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 144 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 145 | |
| 146 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 147 | Consumer::StopApplication() // Called at time specified by Stop |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 148 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 149 | NS_LOG_FUNCTION_NOARGS(); |
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 | // cancel periodic packet generation |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 152 | Simulator::Cancel(m_sendEvent); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 153 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 154 | // cleanup base stuff |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 155 | App::StopApplication(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 156 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 157 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 158 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 159 | Consumer::SendPacket() |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 160 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 161 | if (!m_active) |
| 162 | return; |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 163 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 164 | NS_LOG_FUNCTION_NOARGS(); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 165 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 166 | uint32_t seq = std::numeric_limits<uint32_t>::max(); // invalid |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 167 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 168 | while (m_retxSeqs.size()) { |
| 169 | seq = *m_retxSeqs.begin(); |
| 170 | m_retxSeqs.erase(m_retxSeqs.begin()); |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | if (seq == std::numeric_limits<uint32_t>::max()) { |
| 175 | if (m_seqMax != std::numeric_limits<uint32_t>::max()) { |
| 176 | if (m_seq >= m_seqMax) { |
| 177 | return; // we are totally done |
| 178 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 179 | } |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 180 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 181 | seq = m_seq++; |
| 182 | } |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 183 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 184 | // |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 185 | shared_ptr<Name> nameWithSequence = make_shared<Name>(m_interestName); |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 186 | nameWithSequence->appendSequenceNumber(seq); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 187 | // |
| 188 | |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 189 | // shared_ptr<Interest> interest = make_shared<Interest> (); |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 190 | shared_ptr<Interest> interest = make_shared<Interest>(); |
Alexander Afanasyev | d6453cd | 2015-08-20 21:45:36 -0700 | [diff] [blame] | 191 | interest->setNonce(m_rand->GetValue(0, std::numeric_limits<uint32_t>::max())); |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 192 | interest->setName(*nameWithSequence); |
| 193 | time::milliseconds interestLifeTime(m_interestLifeTime.GetMilliSeconds()); |
| 194 | interest->setInterestLifetime(interestLifeTime); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 195 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 196 | // NS_LOG_INFO ("Requesting Interest: \n" << *interest); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 197 | NS_LOG_INFO("> Interest for " << seq); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 198 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 199 | WillSendOutInterest(seq); |
Alexander Afanasyev | e1aa9b9 | 2012-10-11 10:40:02 -0700 | [diff] [blame] | 200 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 201 | m_transmittedInterests(interest, this, m_face); |
Alexander Afanasyev | 50ea1a3 | 2016-09-08 15:44:08 -0700 | [diff] [blame] | 202 | m_appLink->onReceiveInterest(*interest); |
Alexander Afanasyev | e1aa9b9 | 2012-10-11 10:40:02 -0700 | [diff] [blame] | 203 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 204 | ScheduleNextPacket(); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 205 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 206 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 207 | /////////////////////////////////////////////////// |
| 208 | // Process incoming packets // |
| 209 | /////////////////////////////////////////////////// |
| 210 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 211 | void |
Spyridon Mastorakis | 53e922f | 2014-10-17 17:29:26 -0700 | [diff] [blame] | 212 | Consumer::OnData(shared_ptr<const Data> data) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 213 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 214 | if (!m_active) |
| 215 | return; |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 216 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 217 | App::OnData(data); // tracing inside |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 218 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 219 | NS_LOG_FUNCTION(this << data); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 220 | |
Alexander Afanasyev | faa01f9 | 2013-07-10 18:34:31 -0700 | [diff] [blame] | 221 | // NS_LOG_INFO ("Received content object: " << boost::cref(*data)); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 222 | |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 223 | // This could be a problem...... |
| 224 | uint32_t seq = data->getName().at(-1).toSequenceNumber(); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 225 | NS_LOG_INFO("< DATA for " << seq); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 226 | |
Alexander Afanasyev | 18d8bc9 | 2015-08-13 18:26:40 -0700 | [diff] [blame] | 227 | int hopCount = 0; |
Spyridon Mastorakis | 73df9f5 | 2016-12-07 14:34:13 -0800 | [diff] [blame] | 228 | auto hopCountTag = data->getTag<lp::HopCountTag>(); |
| 229 | if (hopCountTag != nullptr) { // e.g., packet came from local node's cache |
| 230 | hopCount = *hopCountTag; |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 231 | } |
Spyridon Mastorakis | 73df9f5 | 2016-12-07 14:34:13 -0800 | [diff] [blame] | 232 | NS_LOG_DEBUG("Hop count: " << hopCount); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 233 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 234 | SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find(seq); |
| 235 | if (entry != m_seqLastDelay.end()) { |
| 236 | m_lastRetransmittedInterestDataDelay(this, seq, Simulator::Now() - entry->time, hopCount); |
| 237 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 238 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 239 | entry = m_seqFullDelay.find(seq); |
| 240 | if (entry != m_seqFullDelay.end()) { |
Mickey Sweatt | 89046c1 | 2014-11-16 20:32:27 -0800 | [diff] [blame] | 241 | m_firstInterestDataDelay(this, seq, Simulator::Now() - entry->time, m_seqRetxCounts[seq], hopCount); |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 242 | } |
Alexander Afanasyev | 400aae1 | 2013-01-19 13:27:52 -0800 | [diff] [blame] | 243 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 244 | m_seqRetxCounts.erase(seq); |
| 245 | m_seqFullDelay.erase(seq); |
| 246 | m_seqLastDelay.erase(seq); |
Alexander Afanasyev | 3a3ce1a | 2013-01-31 11:26:11 -0800 | [diff] [blame] | 247 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 248 | m_seqTimeouts.erase(seq); |
| 249 | m_retxSeqs.erase(seq); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 250 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 251 | m_rtt->AckSeq(SequenceNumber32(seq)); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void |
Spyridon Mastorakis | 7f2fd42 | 2016-12-07 14:33:59 -0800 | [diff] [blame] | 255 | Consumer::OnNack(shared_ptr<const lp::Nack> nack) |
| 256 | { |
| 257 | /// tracing inside |
| 258 | App::OnNack(nack); |
| 259 | |
| 260 | NS_LOG_INFO("NACK received for: " << nack->getInterest().getName() |
| 261 | << ", reason: " << nack->getReason()); |
| 262 | } |
| 263 | |
| 264 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 265 | Consumer::OnTimeout(uint32_t sequenceNumber) |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 266 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 267 | NS_LOG_FUNCTION(sequenceNumber); |
| 268 | // std::cout << Simulator::Now () << ", TO: " << sequenceNumber << ", current RTO: " << |
| 269 | // m_rtt->RetransmitTimeout ().ToDouble (Time::S) << "s\n"; |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 270 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 271 | m_rtt->IncreaseMultiplier(); // Double the next RTO |
| 272 | m_rtt->SentSeq(SequenceNumber32(sequenceNumber), |
| 273 | 1); // make sure to disable RTT calculation for this sample |
| 274 | m_retxSeqs.insert(sequenceNumber); |
| 275 | ScheduleNextPacket(); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 278 | void |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 279 | Consumer::WillSendOutInterest(uint32_t sequenceNumber) |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 280 | { |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 281 | NS_LOG_DEBUG("Trying to add " << sequenceNumber << " with " << Simulator::Now() << ". already " |
| 282 | << m_seqTimeouts.size() << " items"); |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 283 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 284 | m_seqTimeouts.insert(SeqTimeout(sequenceNumber, Simulator::Now())); |
| 285 | m_seqFullDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now())); |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 286 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 287 | m_seqLastDelay.erase(sequenceNumber); |
| 288 | m_seqLastDelay.insert(SeqTimeout(sequenceNumber, Simulator::Now())); |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 289 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 290 | m_seqRetxCounts[sequenceNumber]++; |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 291 | |
Alexander Afanasyev | be55cf6 | 2014-12-20 17:51:09 -0800 | [diff] [blame] | 292 | m_rtt->SentSeq(SequenceNumber32(sequenceNumber), 1); |
Alexander Afanasyev | 79b2fb3 | 2013-04-12 11:24:55 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 295 | } // namespace ndn |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 296 | } // namespace ns3 |