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 | |
| 21 | #include "ccnx-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 | |
| 32 | #include "ns3/ccnx.h" |
Alexander Afanasyev | f9f4eb0 | 2011-12-16 01:51:14 -0800 | [diff] [blame] | 33 | #include "../model/ccnx-local-face.h" |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 34 | #include "ns3/ccnx-interest-header.h" |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 35 | #include "ns3/ccnx-content-object-header.h" |
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 | #include <boost/lexical_cast.hpp> |
| 39 | #include <boost/lambda/lambda.hpp> |
| 40 | #include <boost/lambda/bind.hpp> |
| 41 | |
| 42 | namespace ll = boost::lambda; |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 43 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 44 | NS_LOG_COMPONENT_DEFINE ("CcnxConsumer"); |
| 45 | |
| 46 | namespace ns3 |
| 47 | { |
| 48 | |
| 49 | NS_OBJECT_ENSURE_REGISTERED (CcnxConsumer); |
| 50 | |
| 51 | TypeId |
| 52 | CcnxConsumer::GetTypeId (void) |
| 53 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 54 | static TypeId tid = TypeId ("ns3::CcnxConsumer") |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 55 | .SetParent<CcnxApp> () |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 56 | .AddConstructor<CcnxConsumer> () |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 57 | .AddAttribute ("StartSeq", "Initial sequence number", |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 58 | IntegerValue (0), |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 59 | MakeIntegerAccessor(&CcnxConsumer::m_seq), |
| 60 | MakeIntegerChecker<int32_t>()) |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 61 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 62 | .AddAttribute ("Size", "Amount of data in megabytes to request (relies on PayloadSize parameter)", |
| 63 | DoubleValue (-1), // don't impose limit by default |
| 64 | MakeDoubleAccessor (&CcnxConsumer::GetMaxSize, &CcnxConsumer::SetMaxSize), |
| 65 | MakeDoubleChecker<double> ()) |
| 66 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 67 | /////// |
| 68 | .AddAttribute ("PayloadSize", "Average size of content object size (to calculate interest generation rate)", |
| 69 | UintegerValue (1040), |
| 70 | MakeUintegerAccessor (&CcnxConsumer::GetPayloadSize, &CcnxConsumer::SetPayloadSize), |
| 71 | MakeUintegerChecker<uint32_t>()) |
| 72 | .AddAttribute ("MeanRate", "Mean data packet rate (relies on the PayloadSize parameter)", |
| 73 | StringValue ("100Kbps"), |
| 74 | MakeDataRateAccessor (&CcnxConsumer::GetDesiredRate, &CcnxConsumer::SetDesiredRate), |
| 75 | MakeDataRateChecker ()) |
| 76 | /////// |
| 77 | |
Alexander Afanasyev | 4975f73 | 2011-12-20 17:52:19 -0800 | [diff] [blame] | 78 | .AddAttribute ("Prefix","CcnxName of the Interest", |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 79 | StringValue ("/"), |
| 80 | MakeCcnxNameComponentsAccessor (&CcnxConsumer::m_interestName), |
| 81 | MakeCcnxNameComponentsChecker ()) |
| 82 | .AddAttribute ("LifeTime", "LifeTime fo interest packet", |
| 83 | StringValue ("2s"), |
| 84 | MakeTimeAccessor (&CcnxConsumer::m_interestLifeTime), |
| 85 | MakeTimeChecker ()) |
| 86 | .AddAttribute ("MinSuffixComponents", "MinSuffixComponents", |
| 87 | IntegerValue(-1), |
| 88 | MakeIntegerAccessor(&CcnxConsumer::m_minSuffixComponents), |
| 89 | MakeIntegerChecker<int32_t>()) |
| 90 | .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents", |
| 91 | IntegerValue(-1), |
| 92 | MakeIntegerAccessor(&CcnxConsumer::m_maxSuffixComponents), |
| 93 | MakeIntegerChecker<int32_t>()) |
| 94 | .AddAttribute ("ChildSelector", "ChildSelector", |
| 95 | BooleanValue(false), |
| 96 | MakeBooleanAccessor(&CcnxConsumer::m_childSelector), |
| 97 | MakeBooleanChecker()) |
| 98 | .AddAttribute ("Exclude", "only simple name matching is supported (use CcnxNameComponents)", |
| 99 | CcnxNameComponentsValue (), |
| 100 | MakeCcnxNameComponentsAccessor (&CcnxConsumer::m_exclude), |
| 101 | MakeCcnxNameComponentsChecker ()) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 102 | |
| 103 | .AddAttribute ("RTO", |
| 104 | "Initial retransmission timeout", |
| 105 | StringValue ("1s"), |
| 106 | MakeTimeAccessor (&CcnxConsumer::m_rto), |
| 107 | MakeTimeChecker ()) |
| 108 | .AddAttribute ("RetxTimer", |
| 109 | "Timeout defining how frequent retransmission timeouts should be checked", |
| 110 | StringValue ("1s"), |
| 111 | MakeTimeAccessor (&CcnxConsumer::GetRetxTimer, &CcnxConsumer::SetRetxTimer), |
| 112 | MakeTimeChecker ()) |
| 113 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 114 | .AddTraceSource ("TransmittedInterests", "TransmittedInterests", |
| 115 | MakeTraceSourceAccessor (&CcnxConsumer::m_transmittedInterests)) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 116 | ; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 117 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 118 | return tid; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | CcnxConsumer::CcnxConsumer () |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 122 | : m_rand (0, std::numeric_limits<uint32_t>::max ()) |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 123 | , m_desiredRate ("10Kbps") |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame^] | 124 | , m_payloadSize (1040) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 125 | , m_seq (0) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 126 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 127 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 128 | |
| 129 | UpdateMean (); // not necessary (will be called by ns3 object system anyways), but doesn't hurt |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 130 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 131 | |
| 132 | void |
| 133 | CcnxConsumer::SetRetxTimer (Time retxTimer) |
| 134 | { |
| 135 | m_retxTimer = retxTimer; |
| 136 | if (m_retxEvent.IsRunning ()) |
| 137 | m_retxEvent.Cancel (); // cancel any scheduled cleanup events |
| 138 | |
| 139 | // schedule even with new timeout |
| 140 | m_retxEvent = Simulator::Schedule (m_retxTimer, |
| 141 | &CcnxConsumer::CheckRetxTimeout, this); |
| 142 | } |
| 143 | |
| 144 | Time |
| 145 | CcnxConsumer::GetRetxTimer () const |
| 146 | { |
| 147 | return m_retxTimer; |
| 148 | } |
| 149 | |
| 150 | void |
| 151 | CcnxConsumer::CheckRetxTimeout () |
| 152 | { |
| 153 | Time now = Simulator::Now (); |
| 154 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 155 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 156 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 157 | while (!m_seqTimeouts.empty ()) |
| 158 | { |
| 159 | SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry = |
| 160 | m_seqTimeouts.get<i_timestamp> ().begin (); |
| 161 | if (entry->time + m_rto <= now) // timeout expired? |
| 162 | { |
| 163 | m_retxSeqs.insert (entry->seq); |
| 164 | m_seqTimeouts.get<i_timestamp> ().modify (entry, |
| 165 | ll::bind(&SeqTimeout::time, ll::_1) = now); |
| 166 | } |
| 167 | else |
| 168 | break; // nothing else to do. All later packets need not be retransmitted |
| 169 | } |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 170 | |
| 171 | if (m_retxSeqs.size () > 0) |
| 172 | { |
| 173 | ScheduleNextPacket (); |
| 174 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 175 | |
| 176 | m_retxEvent = Simulator::Schedule (m_retxTimer, |
| 177 | &CcnxConsumer::CheckRetxTimeout, this); |
| 178 | } |
| 179 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 180 | void |
| 181 | CcnxConsumer::UpdateMean () |
| 182 | { |
| 183 | double mean = 8.0 * m_payloadSize / m_desiredRate.GetBitRate (); |
| 184 | m_randExp = ExponentialVariable (mean, 10000 * mean); // set upper limit to inter-arrival time |
| 185 | } |
| 186 | |
| 187 | void |
| 188 | CcnxConsumer::SetPayloadSize (uint32_t payload) |
| 189 | { |
| 190 | m_payloadSize = payload; |
| 191 | UpdateMean (); |
| 192 | } |
| 193 | |
| 194 | uint32_t |
| 195 | CcnxConsumer::GetPayloadSize () const |
| 196 | { |
| 197 | return m_payloadSize; |
| 198 | } |
| 199 | |
| 200 | void |
| 201 | CcnxConsumer::SetDesiredRate (DataRate rate) |
| 202 | { |
| 203 | m_desiredRate = rate; |
| 204 | UpdateMean (); |
| 205 | } |
| 206 | |
| 207 | DataRate |
| 208 | CcnxConsumer::GetDesiredRate () const |
| 209 | { |
| 210 | return m_desiredRate; |
| 211 | } |
| 212 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 213 | double |
| 214 | CcnxConsumer::GetMaxSize () const |
| 215 | { |
| 216 | if (m_seqMax == 0) |
| 217 | return -1.0; |
| 218 | |
| 219 | return m_seqMax * m_payloadSize / 1024.0 / 1024.0; |
| 220 | } |
| 221 | |
| 222 | void |
| 223 | CcnxConsumer::SetMaxSize (double size) |
| 224 | { |
| 225 | if (size < 0) |
| 226 | { |
| 227 | m_seqMax = 0; |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | m_seqMax = floor(1.0 + size * 1024.0 * 1024.0 / m_payloadSize); |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 232 | NS_LOG_DEBUG ("MaxSeqNo: " << m_seqMax); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame^] | 233 | |
| 234 | std::cout << "MaxSeqNo = " << m_seqMax << "\n"; |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 238 | void |
| 239 | CcnxConsumer::ScheduleNextPacket () |
| 240 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 241 | if (!m_sendEvent.IsRunning ()) |
| 242 | m_sendEvent = Simulator::Schedule ( |
| 243 | Seconds(m_randExp.GetValue ()), |
| 244 | &CcnxConsumer::SendPacket, this); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 247 | // Application Methods |
| 248 | void |
| 249 | CcnxConsumer::StartApplication () // Called at time specified by Start |
| 250 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 251 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 252 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 253 | // do base stuff |
| 254 | CcnxApp::StartApplication (); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 255 | |
| 256 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | void |
| 260 | CcnxConsumer::StopApplication () // Called at time specified by Stop |
| 261 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 262 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 263 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 264 | // cancel periodic packet generation |
| 265 | Simulator::Cancel (m_sendEvent); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 266 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 267 | // cleanup base stuff |
| 268 | CcnxApp::StopApplication (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 271 | void |
| 272 | CcnxConsumer::SendPacket () |
| 273 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 274 | if (!m_active) return; |
| 275 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 276 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 277 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 278 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 279 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 280 | uint32_t seq; |
| 281 | |
| 282 | if (m_retxSeqs.size () != 0) |
| 283 | { |
| 284 | seq = *m_retxSeqs.begin (); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 285 | NS_LOG_INFO ("Before: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 286 | m_retxSeqs.erase (m_retxSeqs.begin ()); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 287 | NS_LOG_INFO ("After: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 288 | } |
| 289 | else |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 290 | { |
| 291 | if (m_seqMax > 0) |
| 292 | { |
| 293 | if (m_seq >= m_seqMax) |
| 294 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 295 | return; // we are totally done |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
| 299 | seq = m_seq++; |
| 300 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 301 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 302 | // |
| 303 | Ptr<CcnxNameComponents> nameWithSequence = Create<CcnxNameComponents> (m_interestName); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 304 | (*nameWithSequence) (seq); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 305 | // |
| 306 | |
| 307 | CcnxInterestHeader interestHeader; |
| 308 | interestHeader.SetNonce (m_rand.GetValue ()); |
| 309 | interestHeader.SetName (nameWithSequence); |
| 310 | interestHeader.SetInterestLifetime (m_interestLifeTime); |
| 311 | interestHeader.SetChildSelector (m_childSelector); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 312 | if (m_exclude.size ()>0) |
| 313 | { |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 314 | interestHeader.SetExclude (Create<CcnxNameComponents> (m_exclude)); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 315 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 316 | interestHeader.SetMaxSuffixComponents (m_maxSuffixComponents); |
| 317 | interestHeader.SetMinSuffixComponents (m_minSuffixComponents); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 318 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 319 | // NS_LOG_INFO ("Requesting Interest: \n" << interestHeader); |
| 320 | NS_LOG_INFO ("> Interest for " << seq); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 321 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 322 | Ptr<Packet> packet = Create<Packet> (); |
| 323 | packet->AddHeader (interestHeader); |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 324 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 325 | m_protocolHandler (packet); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 326 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 327 | NS_LOG_DEBUG ("Trying to add " << seq << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items"); |
| 328 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 329 | std::pair<SeqTimeoutsContainer::iterator, bool> |
| 330 | res = m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ())); |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 331 | |
Alexander Afanasyev | a845f72 | 2011-12-16 13:11:02 -0800 | [diff] [blame] | 332 | if (!res.second) |
| 333 | m_seqTimeouts.modify (res.first, |
| 334 | ll::bind(&SeqTimeout::time, ll::_1) = Simulator::Now ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 335 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 336 | m_transmittedInterests (&interestHeader, this, m_face); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 337 | |
| 338 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 339 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 340 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 341 | /////////////////////////////////////////////////// |
| 342 | // Process incoming packets // |
| 343 | /////////////////////////////////////////////////// |
| 344 | |
| 345 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 346 | void |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 347 | CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject, |
| 348 | const Ptr<const Packet> &payload) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 349 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 350 | if (!m_active) return; |
| 351 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 352 | CcnxApp::OnContentObject (contentObject, payload); // tracing inside |
| 353 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 354 | NS_LOG_FUNCTION (this << contentObject << payload); |
| 355 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 356 | // NS_LOG_INFO ("Received content object: " << boost::cref(*contentObject)); |
| 357 | |
| 358 | uint32_t seq = boost::lexical_cast<uint32_t> (contentObject->GetName ().GetComponents ().back ()); |
| 359 | NS_LOG_INFO ("< DATA for " << seq); |
| 360 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 361 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 362 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 363 | SeqTimeoutsContainer::iterator entry = m_seqTimeouts.find (seq); |
| 364 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 365 | // NS_ASSERT_MSG (entry != m_seqTimeouts.end (), |
| 366 | // "Comment out this assert, if it causes problems"); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 367 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame^] | 368 | // if (entry != m_seqTimeouts.end ()) |
| 369 | // m_seqTimeouts.erase (entry); |
| 370 | |
| 371 | m_seqTimeouts.erase (seq); |
| 372 | m_retxSeqs.erase (seq); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | void |
| 376 | CcnxConsumer::OnNack (const Ptr<const CcnxInterestHeader> &interest) |
| 377 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 378 | if (!m_active) return; |
| 379 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 380 | CcnxApp::OnNack (interest); // tracing inside |
| 381 | |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 382 | NS_LOG_DEBUG ("Nack type: " << interest->GetNack ()); |
| 383 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 384 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 385 | NS_LOG_FUNCTION (this << interest); |
| 386 | |
| 387 | // NS_LOG_INFO ("Received NACK: " << boost::cref(*interest)); |
| 388 | uint32_t seq = boost::lexical_cast<uint32_t> (interest->GetName ().GetComponents ().back ()); |
| 389 | NS_LOG_INFO ("< NACK for " << seq); |
| 390 | |
| 391 | // put in the queue of interests to be retransmitted |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 392 | NS_LOG_INFO ("Before: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 393 | m_retxSeqs.insert (seq); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 394 | NS_LOG_INFO ("After: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 395 | |
| 396 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 397 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 398 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 399 | } // namespace ns3 |