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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 21 | #include "ndn-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 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 32 | #include "ns3/ndn-app-face.h" |
| 33 | #include "ns3/ndn-interest-header.h" |
| 34 | #include "ns3/ndn-content-object-header.h" |
Alexander Afanasyev | de7601a | 2012-05-31 12:14:54 -0700 | [diff] [blame] | 35 | // #include "ns3/weights-path-stretch-tag.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 | |
Alexander Afanasyev | 3661e23 | 2012-01-20 17:36:15 -0800 | [diff] [blame] | 42 | #include "ns3/names.h" |
| 43 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 44 | namespace ll = boost::lambda; |
Alexander Afanasyev | 19426ef | 2011-11-23 20:55:28 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 46 | NS_LOG_COMPONENT_DEFINE ("ndn.Consumer"); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 47 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 48 | namespace ns3 { |
| 49 | namespace ndn { |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 50 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 51 | NS_OBJECT_ENSURE_REGISTERED (Consumer); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 52 | |
| 53 | TypeId |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 54 | Consumer::GetTypeId (void) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 55 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 56 | static TypeId tid = TypeId ("ns3::ndn::Consumer") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 57 | .SetGroupName ("Ndn") |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 58 | .SetParent<App> () |
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 | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 61 | MakeIntegerAccessor(&Consumer::m_seq), |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 62 | MakeIntegerChecker<int32_t>()) |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 63 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 64 | .AddAttribute ("Prefix","Name of the Interest", |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 65 | StringValue ("/"), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 66 | MakeNameComponentsAccessor (&Consumer::m_interestName), |
| 67 | MakeNameComponentsChecker ()) |
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"), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 70 | MakeTimeAccessor (&Consumer::m_interestLifeTime), |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 71 | MakeTimeChecker ()) |
| 72 | .AddAttribute ("MinSuffixComponents", "MinSuffixComponents", |
| 73 | IntegerValue(-1), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 74 | MakeIntegerAccessor(&Consumer::m_minSuffixComponents), |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 75 | MakeIntegerChecker<int32_t>()) |
| 76 | .AddAttribute ("MaxSuffixComponents", "MaxSuffixComponents", |
| 77 | IntegerValue(-1), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 78 | MakeIntegerAccessor(&Consumer::m_maxSuffixComponents), |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 79 | MakeIntegerChecker<int32_t>()) |
| 80 | .AddAttribute ("ChildSelector", "ChildSelector", |
| 81 | BooleanValue(false), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 82 | MakeBooleanAccessor(&Consumer::m_childSelector), |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 83 | MakeBooleanChecker()) |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 84 | .AddAttribute ("Exclude", "only simple name matching is supported (use NameComponents)", |
| 85 | NameComponentsValue (), |
| 86 | MakeNameComponentsAccessor (&Consumer::m_exclude), |
| 87 | MakeNameComponentsChecker ()) |
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 | 3d0c2e0 | 2012-01-22 18:50:05 -0800 | [diff] [blame] | 91 | StringValue ("50ms"), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 92 | MakeTimeAccessor (&Consumer::GetRetxTimer, &Consumer::SetRetxTimer), |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 93 | MakeTimeChecker ()) |
| 94 | |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 95 | .AddTraceSource ("PathWeightsTrace", "PathWeightsTrace", |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 96 | MakeTraceSourceAccessor (&Consumer::m_pathWeightsTrace)) |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 97 | ; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 98 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 99 | return tid; |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 102 | Consumer::Consumer () |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 103 | : m_rand (0, std::numeric_limits<uint32_t>::max ()) |
| 104 | , m_seq (0) |
Alexander Afanasyev | b7ad232 | 2012-01-17 22:54:49 -0800 | [diff] [blame] | 105 | , m_seqMax (0) // don't request anything |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 106 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 107 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 108 | |
Alexander Afanasyev | 94cebd0 | 2012-01-16 12:22:34 -0800 | [diff] [blame] | 109 | m_rtt = CreateObject<RttMeanDeviation> (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 110 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 111 | |
| 112 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 113 | Consumer::SetRetxTimer (Time retxTimer) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 114 | { |
| 115 | m_retxTimer = retxTimer; |
| 116 | if (m_retxEvent.IsRunning ()) |
Alexander Afanasyev | b18ae02 | 2012-09-03 21:46:36 -0700 | [diff] [blame] | 117 | { |
| 118 | // m_retxEvent.Cancel (); // cancel any scheduled cleanup events |
| 119 | Simulator::Remove (m_retxEvent); // slower, but better for memory |
| 120 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 121 | |
| 122 | // schedule even with new timeout |
| 123 | m_retxEvent = Simulator::Schedule (m_retxTimer, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 124 | &Consumer::CheckRetxTimeout, this); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | Time |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 128 | Consumer::GetRetxTimer () const |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 129 | { |
| 130 | return m_retxTimer; |
| 131 | } |
| 132 | |
| 133 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 134 | Consumer::CheckRetxTimeout () |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 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 (); |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 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 | e0e5bd1 | 2012-01-21 14:30:52 -0800 | [diff] [blame] | 146 | uint32_t seqNo = entry->seq; |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 147 | m_seqTimeouts.get<i_timestamp> ().erase (entry); |
Alexander Afanasyev | e0e5bd1 | 2012-01-21 14:30:52 -0800 | [diff] [blame] | 148 | OnTimeout (seqNo); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 149 | } |
| 150 | else |
| 151 | break; // nothing else to do. All later packets need not be retransmitted |
| 152 | } |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 153 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 154 | m_retxEvent = Simulator::Schedule (m_retxTimer, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 155 | &Consumer::CheckRetxTimeout, this); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 156 | } |
| 157 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 158 | // Application Methods |
| 159 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 160 | Consumer::StartApplication () // Called at time specified by Start |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 161 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 162 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 163 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 164 | // do base stuff |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 165 | App::StartApplication (); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 166 | |
| 167 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 171 | Consumer::StopApplication () // Called at time specified by Stop |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 172 | { |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 173 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 174 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 175 | // cancel periodic packet generation |
| 176 | Simulator::Cancel (m_sendEvent); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 177 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 178 | // cleanup base stuff |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 179 | App::StopApplication (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 182 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 183 | Consumer::SendPacket () |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 184 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 185 | if (!m_active) return; |
| 186 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 187 | NS_LOG_FUNCTION_NOARGS (); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 188 | |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 189 | uint32_t seq=std::numeric_limits<uint32_t>::max (); //invalid |
| 190 | |
Alexander Afanasyev | 1180b04 | 2012-01-25 19:26:13 -0800 | [diff] [blame] | 191 | // std::cout << Simulator::Now ().ToDouble (Time::S) << "s max -> " << m_seqMax << "\n"; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 192 | |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 193 | while (m_retxSeqs.size ()) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 194 | { |
| 195 | seq = *m_retxSeqs.begin (); |
| 196 | m_retxSeqs.erase (m_retxSeqs.begin ()); |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 197 | |
| 198 | // NS_ASSERT (m_seqLifetimes.find (seq) != m_seqLifetimes.end ()); |
| 199 | // if (m_seqLifetimes.find (seq)->time <= Simulator::Now ()) |
| 200 | // { |
| 201 | |
| 202 | // NS_LOG_DEBUG ("Expire " << seq); |
| 203 | // m_seqLifetimes.erase (seq); // lifetime expired. Trying to find another unexpired sequence number |
| 204 | // continue; |
| 205 | // } |
| 206 | break; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 207 | } |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 208 | |
| 209 | if (seq == std::numeric_limits<uint32_t>::max ()) |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 210 | { |
Alexander Afanasyev | 812f7ab | 2012-01-24 11:08:04 -0800 | [diff] [blame] | 211 | if (m_seqMax != std::numeric_limits<uint32_t>::max ()) |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 212 | { |
| 213 | if (m_seq >= m_seqMax) |
| 214 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 215 | return; // we are totally done |
Alexander Afanasyev | b3e4b85 | 2011-12-23 15:58:20 -0800 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
| 219 | seq = m_seq++; |
| 220 | } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 221 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 222 | // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << seq << "\n"; |
Ilya Moiseenko | 0605d26 | 2011-10-28 13:00:07 -0700 | [diff] [blame] | 223 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 224 | // |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 225 | Ptr<NameComponents> nameWithSequence = Create<NameComponents> (m_interestName); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 226 | (*nameWithSequence) (seq); |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 227 | // |
| 228 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 229 | InterestHeader interestHeader; |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 230 | interestHeader.SetNonce (m_rand.GetValue ()); |
| 231 | interestHeader.SetName (nameWithSequence); |
| 232 | interestHeader.SetInterestLifetime (m_interestLifeTime); |
| 233 | interestHeader.SetChildSelector (m_childSelector); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 234 | if (m_exclude.size ()>0) |
| 235 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 236 | interestHeader.SetExclude (Create<NameComponents> (m_exclude)); |
Alexander Afanasyev | c39f0b4 | 2011-11-28 12:51:12 -0800 | [diff] [blame] | 237 | } |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 238 | interestHeader.SetMaxSuffixComponents (m_maxSuffixComponents); |
| 239 | interestHeader.SetMinSuffixComponents (m_minSuffixComponents); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 240 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 241 | // NS_LOG_INFO ("Requesting Interest: \n" << interestHeader); |
| 242 | NS_LOG_INFO ("> Interest for " << seq); |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 243 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 244 | Ptr<Packet> packet = Create<Packet> (); |
| 245 | packet->AddHeader (interestHeader); |
Alexander Afanasyev | 59e6771 | 2012-02-07 11:49:34 -0800 | [diff] [blame] | 246 | NS_LOG_DEBUG ("Interest packet size: " << packet->GetSize ()); |
Alexander Afanasyev | d02a5d6 | 2011-11-21 11:01:51 -0800 | [diff] [blame] | 247 | |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 248 | NS_LOG_DEBUG ("Trying to add " << seq << " with " << Simulator::Now () << ". already " << m_seqTimeouts.size () << " items"); |
| 249 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 250 | m_seqTimeouts.insert (SeqTimeout (seq, Simulator::Now ())); |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 251 | m_seqLifetimes.insert (SeqTimeout (seq, Simulator::Now () + m_interestLifeTime)); // only one insert will work. if entry exists, nothing will happen... nothing should happen |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 252 | m_transmittedInterests (&interestHeader, this, m_face); |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 253 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 254 | m_rtt->SentSeq (SequenceNumber32 (seq), 1); |
Alexander Afanasyev | e1aa9b9 | 2012-10-11 10:40:02 -0700 | [diff] [blame] | 255 | |
| 256 | m_protocolHandler (packet); |
| 257 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 258 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 259 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 260 | |
Alexander Afanasyev | 011b859 | 2011-12-21 14:45:27 -0800 | [diff] [blame] | 261 | /////////////////////////////////////////////////// |
| 262 | // Process incoming packets // |
| 263 | /////////////////////////////////////////////////// |
| 264 | |
| 265 | |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 266 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 267 | Consumer::OnContentObject (const Ptr<const ContentObjectHeader> &contentObject, |
Alexander Afanasyev | e9c9d72 | 2012-01-19 16:59:30 -0800 | [diff] [blame] | 268 | Ptr<Packet> payload) |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 269 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 270 | if (!m_active) return; |
| 271 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 272 | App::OnContentObject (contentObject, payload); // tracing inside |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 273 | |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 274 | NS_LOG_FUNCTION (this << contentObject << payload); |
| 275 | |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 276 | // NS_LOG_INFO ("Received content object: " << boost::cref(*contentObject)); |
| 277 | |
| 278 | uint32_t seq = boost::lexical_cast<uint32_t> (contentObject->GetName ().GetComponents ().back ()); |
| 279 | NS_LOG_INFO ("< DATA for " << seq); |
| 280 | |
Alexander Afanasyev | 8dcfa5d | 2012-01-05 14:22:25 -0700 | [diff] [blame] | 281 | // SeqTimeoutsContainer::iterator entry = m_seqTimeouts.find (seq); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 282 | |
Alexander Afanasyev | 8f5a9bb | 2011-12-18 19:49:02 -0800 | [diff] [blame] | 283 | // NS_ASSERT_MSG (entry != m_seqTimeouts.end (), |
| 284 | // "Comment out this assert, if it causes problems"); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 285 | |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 286 | // if (entry != m_seqTimeouts.end ()) |
| 287 | // m_seqTimeouts.erase (entry); |
| 288 | |
Alexander Afanasyev | 1ec705f | 2012-01-23 12:35:10 -0800 | [diff] [blame] | 289 | m_seqLifetimes.erase (seq); |
Alexander Afanasyev | 36d5c2a | 2012-01-02 19:09:19 -0800 | [diff] [blame] | 290 | m_seqTimeouts.erase (seq); |
| 291 | m_retxSeqs.erase (seq); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 292 | |
| 293 | m_rtt->AckSeq (SequenceNumber32 (seq)); |
Alexander Afanasyev | 6bff0df | 2012-01-19 17:51:52 -0800 | [diff] [blame] | 294 | |
Alexander Afanasyev | de7601a | 2012-05-31 12:14:54 -0700 | [diff] [blame] | 295 | // Ptr<const WeightsPathStretchTag> tag = payload->RemovePacketTag<WeightsPathStretchTag> (); |
| 296 | // if (tag != 0) |
| 297 | // { |
| 298 | // // Notify trace about path weights vector (e.g., for path-stretch calculation) |
| 299 | // m_pathWeightsTrace (GetNode (), tag->GetSourceNode (), seq, tag->GetTotalWeight ()); |
| 300 | // // if (Names::FindName (GetNode ()) == "36")// || Names::FindName (GetNode ()) == "40"|| Names::FindName (GetNode ()) == "5") |
| 301 | // // std::cout << Simulator::Now () << "\t" << boost::cref(*tag) << " = " << tag->GetTotalWeight () << "\n"; |
| 302 | // } |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 306 | Consumer::OnNack (const Ptr<const InterestHeader> &interest, Ptr<Packet> origPacket) |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 307 | { |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 308 | if (!m_active) return; |
| 309 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 310 | App::OnNack (interest, origPacket); // tracing inside |
Alexander Afanasyev | bdc0d98 | 2011-12-16 01:15:26 -0800 | [diff] [blame] | 311 | |
Alexander Afanasyev | e1b2a2d | 2012-11-16 11:53:42 -0800 | [diff] [blame^] | 312 | // NS_LOG_DEBUG ("Nack type: " << interest->GetNack ()); |
Alexander Afanasyev | 120bf31 | 2011-12-19 01:24:47 -0800 | [diff] [blame] | 313 | |
Alexander Afanasyev | e1b2a2d | 2012-11-16 11:53:42 -0800 | [diff] [blame^] | 314 | // NS_LOG_FUNCTION (interest->GetName ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 315 | |
| 316 | // NS_LOG_INFO ("Received NACK: " << boost::cref(*interest)); |
| 317 | uint32_t seq = boost::lexical_cast<uint32_t> (interest->GetName ().GetComponents ().back ()); |
| 318 | NS_LOG_INFO ("< NACK for " << seq); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 319 | // std::cout << Simulator::Now ().ToDouble (Time::S) << "s -> " << "NACK for " << seq << "\n"; |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 320 | |
| 321 | // put in the queue of interests to be retransmitted |
Alexander Afanasyev | e1b2a2d | 2012-11-16 11:53:42 -0800 | [diff] [blame^] | 322 | // NS_LOG_INFO ("Before: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 781ea81 | 2011-12-15 22:42:09 -0800 | [diff] [blame] | 323 | m_retxSeqs.insert (seq); |
Alexander Afanasyev | e1b2a2d | 2012-11-16 11:53:42 -0800 | [diff] [blame^] | 324 | // NS_LOG_INFO ("After: " << m_retxSeqs.size ()); |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 325 | |
Alexander Afanasyev | 92d5be1 | 2012-08-13 18:56:52 -0700 | [diff] [blame] | 326 | m_rtt->IncreaseMultiplier (); // Double the next RTO ?? |
Alexander Afanasyev | 3183b5a | 2011-12-23 20:48:20 -0800 | [diff] [blame] | 327 | ScheduleNextPacket (); |
Ilya Moiseenko | 8196d2e | 2011-08-29 13:03:22 -0700 | [diff] [blame] | 328 | } |
Alexander Afanasyev | c5a23e2 | 2011-09-07 00:37:36 -0700 | [diff] [blame] | 329 | |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 330 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 331 | Consumer::OnTimeout (uint32_t sequenceNumber) |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 332 | { |
Alexander Afanasyev | 92d5be1 | 2012-08-13 18:56:52 -0700 | [diff] [blame] | 333 | NS_LOG_FUNCTION (sequenceNumber); |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 334 | // 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] | 335 | |
Alexander Afanasyev | 92d5be1 | 2012-08-13 18:56:52 -0700 | [diff] [blame] | 336 | m_rtt->IncreaseMultiplier (); // Double the next RTO |
Alexander Afanasyev | 8e0d281 | 2012-01-19 22:38:14 -0800 | [diff] [blame] | 337 | 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] | 338 | m_retxSeqs.insert (sequenceNumber); |
Alexander Afanasyev | 359bfb7 | 2012-01-09 18:42:50 -0800 | [diff] [blame] | 339 | ScheduleNextPacket (); |
| 340 | } |
| 341 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 342 | } // namespace ndn |
Alexander Afanasyev | 09c7deb | 2011-11-23 14:50:10 -0800 | [diff] [blame] | 343 | } // namespace ns3 |