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