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 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 95 | .AddAttribute ("RetxTimer", |
| 96 | "Timeout defining how frequent retransmission timeouts should be checked", |
| 97 | StringValue ("1s"), |
| 98 | MakeTimeAccessor (&CcnxConsumer::GetRetxTimer, &CcnxConsumer::SetRetxTimer), |
| 99 | MakeTimeChecker ()) |
| 100 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 101 | .AddTraceSource ("TransmittedInterests", "TransmittedInterests", |
| 102 | MakeTraceSourceAccessor (&CcnxConsumer::m_transmittedInterests)) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 103 | ; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 104 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 105 | return tid; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | CcnxConsumer::CcnxConsumer () |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 109 | : m_rand (0, std::numeric_limits<uint32_t>::max ()) |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 110 | , m_payloadSize (1040) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 111 | , m_seq (0) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 112 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 113 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 114 | |
| 115 | m_rtt = CreateObject<RttMeanDeviation> (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 116 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 117 | |
| 118 | void |
| 119 | CcnxConsumer::SetRetxTimer (Time retxTimer) |
| 120 | { |
| 121 | m_retxTimer = retxTimer; |
| 122 | if (m_retxEvent.IsRunning ()) |
| 123 | m_retxEvent.Cancel (); // cancel any scheduled cleanup events |
| 124 | |
| 125 | // schedule even with new timeout |
| 126 | m_retxEvent = Simulator::Schedule (m_retxTimer, |
| 127 | &CcnxConsumer::CheckRetxTimeout, this); |
| 128 | } |
| 129 | |
| 130 | Time |
| 131 | CcnxConsumer::GetRetxTimer () const |
| 132 | { |
| 133 | return m_retxTimer; |
| 134 | } |
| 135 | |
| 136 | void |
| 137 | CcnxConsumer::CheckRetxTimeout () |
| 138 | { |
| 139 | Time now = Simulator::Now (); |
| 140 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 141 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 142 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 143 | Time rto = m_rtt->RetransmitTimeout (); |
| 144 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 145 | while (!m_seqTimeouts.empty ()) |
| 146 | { |
| 147 | SeqTimeoutsContainer::index<i_timestamp>::type::iterator entry = |
| 148 | m_seqTimeouts.get<i_timestamp> ().begin (); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 149 | if (entry->time + rto <= now) // timeout expired? |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 150 | { |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 151 | m_seqTimeouts.get<i_timestamp> ().erase (entry); |
| 152 | OnTimeout (entry->seq); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 153 | } |
| 154 | else |
| 155 | break; // nothing else to do. All later packets need not be retransmitted |
| 156 | } |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 157 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 158 | m_retxEvent = Simulator::Schedule (m_retxTimer, |
| 159 | &CcnxConsumer::CheckRetxTimeout, this); |
| 160 | } |
| 161 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 162 | uint32_t |
| 163 | CcnxConsumer::GetPayloadSize () const |
| 164 | { |
| 165 | return m_payloadSize; |
| 166 | } |
| 167 | |
| 168 | void |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 169 | CcnxConsumer::SetPayloadSize (uint32_t payload) |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 170 | { |
Alexander Afanasyev | 029d38d | 2012-01-09 13:50:50 -0800 | [diff] [blame] | 171 | m_payloadSize = payload; |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 174 | double |
| 175 | CcnxConsumer::GetMaxSize () const |
| 176 | { |
| 177 | if (m_seqMax == 0) |
| 178 | return -1.0; |
| 179 | |
| 180 | return m_seqMax * m_payloadSize / 1024.0 / 1024.0; |
| 181 | } |
| 182 | |
| 183 | void |
| 184 | CcnxConsumer::SetMaxSize (double size) |
| 185 | { |
| 186 | if (size < 0) |
| 187 | { |
| 188 | m_seqMax = 0; |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | m_seqMax = floor(1.0 + size * 1024.0 * 1024.0 / m_payloadSize); |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 193 | NS_LOG_DEBUG ("MaxSeqNo: " << m_seqMax); |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 196 | // Application Methods |
| 197 | void |
| 198 | CcnxConsumer::StartApplication () // Called at time specified by Start |
| 199 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 200 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 201 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 202 | // do base stuff |
| 203 | CcnxApp::StartApplication (); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 204 | |
| 205 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void |
| 209 | CcnxConsumer::StopApplication () // Called at time specified by Stop |
| 210 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 211 | NS_LOG_FUNCTION_NOARGS (); |
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 | // cancel periodic packet generation |
| 214 | Simulator::Cancel (m_sendEvent); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 215 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 216 | // cleanup base stuff |
| 217 | CcnxApp::StopApplication (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 220 | void |
| 221 | CcnxConsumer::SendPacket () |
| 222 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 223 | if (!m_active) return; |
| 224 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 225 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 226 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 227 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 228 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 229 | uint32_t seq; |
| 230 | |
| 231 | if (m_retxSeqs.size () != 0) |
| 232 | { |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 233 | // for (RetxSeqsContainer::const_iterator i=m_retxSeqs.begin (); i!=m_retxSeqs.end (); i++) |
| 234 | // { |
| 235 | // std::cout << *i << " "; |
| 236 | // } |
| 237 | // std::cout << "\n"; |
| 238 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 239 | seq = *m_retxSeqs.begin (); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 240 | NS_LOG_INFO ("Before: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 241 | m_retxSeqs.erase (m_retxSeqs.begin ()); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 242 | NS_LOG_INFO ("After: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 243 | } |
| 244 | else |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 245 | { |
| 246 | if (m_seqMax > 0) |
| 247 | { |
| 248 | if (m_seq >= m_seqMax) |
| 249 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 250 | return; // we are totally done |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | |
| 254 | seq = m_seq++; |
| 255 | } |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 256 | |
| 257 | // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << seq << "\n"; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 258 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 259 | // |
| 260 | Ptr<CcnxNameComponents> nameWithSequence = Create<CcnxNameComponents> (m_interestName); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 261 | (*nameWithSequence) (seq); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 262 | // |
| 263 | |
| 264 | CcnxInterestHeader interestHeader; |
| 265 | interestHeader.SetNonce (m_rand.GetValue ()); |
| 266 | interestHeader.SetName (nameWithSequence); |
| 267 | interestHeader.SetInterestLifetime (m_interestLifeTime); |
| 268 | interestHeader.SetChildSelector (m_childSelector); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 269 | if (m_exclude.size ()>0) |
| 270 | { |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 271 | interestHeader.SetExclude (Create<CcnxNameComponents> (m_exclude)); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 272 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 273 | interestHeader.SetMaxSuffixComponents (m_maxSuffixComponents); |
| 274 | interestHeader.SetMinSuffixComponents (m_minSuffixComponents); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 275 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 276 | // NS_LOG_INFO ("Requesting Interest: \n" << interestHeader); |
| 277 | NS_LOG_INFO ("> Interest for " << seq); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 278 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 279 | Ptr<Packet> packet = Create<Packet> (); |
| 280 | packet->AddHeader (interestHeader); |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 281 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 282 | m_protocolHandler (packet); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 283 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 284 | NS_LOG_DEBUG ("Trying to add " << seq << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items"); |
| 285 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 286 | m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ())); |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 287 | m_transmittedInterests (&interestHeader, this, m_face); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 288 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 289 | m_rtt->SentSeq (SequenceNumber32 (seq), 1); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 290 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 291 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 292 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 293 | /////////////////////////////////////////////////// |
| 294 | // Process incoming packets // |
| 295 | /////////////////////////////////////////////////// |
| 296 | |
| 297 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 298 | void |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 299 | CcnxConsumer::OnContentObject (const Ptr<const CcnxContentObjectHeader> &contentObject, |
| 300 | const Ptr<const Packet> &payload) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 301 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 302 | if (!m_active) return; |
| 303 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 304 | CcnxApp::OnContentObject (contentObject, payload); // tracing inside |
| 305 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 306 | NS_LOG_FUNCTION (this << contentObject << payload); |
| 307 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 308 | // NS_LOG_INFO ("Received content object: " << boost::cref(*contentObject)); |
| 309 | |
| 310 | uint32_t seq = boost::lexical_cast<uint32_t> (contentObject->GetName ().GetComponents ().back ()); |
| 311 | NS_LOG_INFO ("< DATA for " << seq); |
| 312 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 313 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 314 | |
Alexander Afanasyev | 8dcfa5d | 2012-01-05 14:22:25 -0700 | [diff] [blame] | 315 | // SeqTimeoutsContainer::iterator entry = m_seqTimeouts.find (seq); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 316 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 317 | // NS_ASSERT_MSG (entry != m_seqTimeouts.end (), |
| 318 | // "Comment out this assert, if it causes problems"); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 319 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 320 | // if (entry != m_seqTimeouts.end ()) |
| 321 | // m_seqTimeouts.erase (entry); |
| 322 | |
| 323 | m_seqTimeouts.erase (seq); |
| 324 | m_retxSeqs.erase (seq); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 325 | |
| 326 | m_rtt->AckSeq (SequenceNumber32 (seq)); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void |
| 330 | CcnxConsumer::OnNack (const Ptr<const CcnxInterestHeader> &interest) |
| 331 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 332 | if (!m_active) return; |
| 333 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 334 | CcnxApp::OnNack (interest); // tracing inside |
| 335 | |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 336 | NS_LOG_DEBUG ("Nack type: " << interest->GetNack ()); |
| 337 | boost::mutex::scoped_lock (m_seqTimeoutsGuard); |
| 338 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 339 | NS_LOG_FUNCTION (this << interest); |
| 340 | |
| 341 | // NS_LOG_INFO ("Received NACK: " << boost::cref(*interest)); |
| 342 | uint32_t seq = boost::lexical_cast<uint32_t> (interest->GetName ().GetComponents ().back ()); |
| 343 | NS_LOG_INFO ("< NACK for " << seq); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 344 | // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << "NACK for " << seq << "\n"; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 345 | |
| 346 | // put in the queue of interests to be retransmitted |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 347 | NS_LOG_INFO ("Before: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 348 | m_retxSeqs.insert (seq); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 349 | NS_LOG_INFO ("After: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 350 | |
| 351 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 352 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 353 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 354 | void |
| 355 | CcnxConsumer::OnTimeout (uint32_t sequenceNumber) |
| 356 | { |
| 357 | // std::cout << "TO: " << sequenceNumber << "\n"; |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 358 | // std::cout << "Current RTO: " << m_rtt->RetransmitTimeout ().ToDouble (Time::S) << "s\n"; |
Alexander Afanasyev | 4d66de5 | 2012-01-13 00:06:01 -0800 | [diff] [blame^] | 359 | m_retxSeqs.insert (sequenceNumber); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 360 | ScheduleNextPacket (); |
| 361 | } |
| 362 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 363 | } // namespace ns3 |