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 | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 236 | void |
| 237 | CcnxConsumer::ScheduleNextPacket () |
| 238 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 239 | if (!m_sendEvent.IsRunning ()) |
| 240 | m_sendEvent = Simulator::Schedule ( |
| 241 | Seconds(m_randExp.GetValue ()), |
| 242 | &CcnxConsumer::SendPacket, this); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 245 | // Application Methods |
| 246 | void |
| 247 | CcnxConsumer::StartApplication () // Called at time specified by Start |
| 248 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 249 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 250 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 251 | // do base stuff |
| 252 | CcnxApp::StartApplication (); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 253 | |
| 254 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void |
| 258 | CcnxConsumer::StopApplication () // Called at time specified by Stop |
| 259 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 260 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 261 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 262 | // cancel periodic packet generation |
| 263 | Simulator::Cancel (m_sendEvent); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 264 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 265 | // cleanup base stuff |
| 266 | CcnxApp::StopApplication (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 269 | void |
| 270 | CcnxConsumer::SendPacket () |
| 271 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 272 | if (!m_active) return; |
| 273 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 274 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 275 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 276 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 277 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 278 | uint32_t seq; |
| 279 | |
| 280 | if (m_retxSeqs.size () != 0) |
| 281 | { |
| 282 | seq = *m_retxSeqs.begin (); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 283 | NS_LOG_INFO ("Before: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 284 | m_retxSeqs.erase (m_retxSeqs.begin ()); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 285 | NS_LOG_INFO ("After: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 286 | } |
| 287 | else |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 288 | { |
| 289 | if (m_seqMax > 0) |
| 290 | { |
| 291 | if (m_seq >= m_seqMax) |
| 292 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 293 | return; // we are totally done |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
| 297 | seq = m_seq++; |
| 298 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 299 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 300 | // |
| 301 | Ptr<CcnxNameComponents> nameWithSequence = Create<CcnxNameComponents> (m_interestName); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 302 | (*nameWithSequence) (seq); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 303 | // |
| 304 | |
| 305 | CcnxInterestHeader interestHeader; |
| 306 | interestHeader.SetNonce (m_rand.GetValue ()); |
| 307 | interestHeader.SetName (nameWithSequence); |
| 308 | interestHeader.SetInterestLifetime (m_interestLifeTime); |
| 309 | interestHeader.SetChildSelector (m_childSelector); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 310 | if (m_exclude.size ()>0) |
| 311 | { |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 312 | interestHeader.SetExclude (Create<CcnxNameComponents> (m_exclude)); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 313 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 314 | interestHeader.SetMaxSuffixComponents (m_maxSuffixComponents); |
| 315 | interestHeader.SetMinSuffixComponents (m_minSuffixComponents); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 316 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 317 | // NS_LOG_INFO ("Requesting Interest: \n" << interestHeader); |
| 318 | NS_LOG_INFO ("> Interest for " << seq); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 319 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 320 | Ptr<Packet> packet = Create<Packet> (); |
| 321 | packet->AddHeader (interestHeader); |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 322 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 323 | m_protocolHandler (packet); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 324 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 325 | NS_LOG_DEBUG ("Trying to add " << seq << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items"); |
| 326 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 327 | std::pair<SeqTimeoutsContainer::iterator, bool> |
| 328 | res = m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ())); |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 329 | |
Alexander Afanasyev | a845f72 | 2011-12-16 13:11:02 -0800 | [diff] [blame] | 330 | if (!res.second) |
| 331 | m_seqTimeouts.modify (res.first, |
| 332 | ll::bind(&SeqTimeout::time, ll::_1) = Simulator::Now ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 333 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 334 | m_transmittedInterests (&interestHeader, this, m_face); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 335 | |
| 336 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 337 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 338 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 339 | /////////////////////////////////////////////////// |
| 340 | // Process incoming packets // |
| 341 | /////////////////////////////////////////////////// |
| 342 | |
| 343 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 344 | void |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 345 | CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject, |
| 346 | const Ptr<const Packet> &payload) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 347 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 348 | if (!m_active) return; |
| 349 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 350 | CcnxApp::OnContentObject (contentObject, payload); // tracing inside |
| 351 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 352 | NS_LOG_FUNCTION (this << contentObject << payload); |
| 353 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 354 | // NS_LOG_INFO ("Received content object: " << boost::cref(*contentObject)); |
| 355 | |
| 356 | uint32_t seq = boost::lexical_cast<uint32_t> (contentObject->GetName ().GetComponents ().back ()); |
| 357 | NS_LOG_INFO ("< DATA for " << seq); |
| 358 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 359 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 360 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 361 | SeqTimeoutsContainer::iterator entry = m_seqTimeouts.find (seq); |
| 362 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 363 | // NS_ASSERT_MSG (entry != m_seqTimeouts.end (), |
| 364 | // "Comment out this assert, if it causes problems"); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 365 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 366 | // if (entry != m_seqTimeouts.end ()) |
| 367 | // m_seqTimeouts.erase (entry); |
| 368 | |
| 369 | m_seqTimeouts.erase (seq); |
| 370 | m_retxSeqs.erase (seq); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | void |
| 374 | CcnxConsumer::OnNack (const Ptr<const CcnxInterestHeader> &interest) |
| 375 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 376 | if (!m_active) return; |
| 377 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 378 | CcnxApp::OnNack (interest); // tracing inside |
| 379 | |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 380 | NS_LOG_DEBUG ("Nack type: " << interest->GetNack ()); |
| 381 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 382 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 383 | NS_LOG_FUNCTION (this << interest); |
| 384 | |
| 385 | // NS_LOG_INFO ("Received NACK: " << boost::cref(*interest)); |
| 386 | uint32_t seq = boost::lexical_cast<uint32_t> (interest->GetName ().GetComponents ().back ()); |
| 387 | NS_LOG_INFO ("< NACK for " << seq); |
| 388 | |
| 389 | // put in the queue of interests to be retransmitted |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 390 | NS_LOG_INFO ("Before: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 391 | m_retxSeqs.insert (seq); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 392 | NS_LOG_INFO ("After: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 393 | |
| 394 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 395 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 396 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 397 | } // namespace ns3 |