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