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