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