Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -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: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | * Ilya Moiseenko <iliamo@cs.ucla.edu> |
| 20 | */ |
| 21 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 22 | #include "ndn-forwarding-strategy.h" |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 24 | #include "ns3/ndn-pit.h" |
| 25 | #include "ns3/ndn-pit-entry.h" |
| 26 | #include "ns3/ndn-interest-header.h" |
| 27 | #include "ns3/ndn-content-object-header.h" |
| 28 | #include "ns3/ndn-pit.h" |
| 29 | #include "ns3/ndn-fib.h" |
| 30 | #include "ns3/ndn-content-store.h" |
| 31 | #include "ns3/ndn-face.h" |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 32 | |
| 33 | #include "ns3/assert.h" |
| 34 | #include "ns3/ptr.h" |
| 35 | #include "ns3/log.h" |
| 36 | #include "ns3/simulator.h" |
| 37 | #include "ns3/boolean.h" |
| 38 | #include "ns3/string.h" |
| 39 | |
| 40 | #include <boost/ref.hpp> |
| 41 | #include <boost/foreach.hpp> |
| 42 | #include <boost/lambda/lambda.hpp> |
| 43 | #include <boost/lambda/bind.hpp> |
| 44 | #include <boost/tuple/tuple.hpp> |
| 45 | namespace ll = boost::lambda; |
| 46 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 47 | NS_LOG_COMPONENT_DEFINE ("ndn.ForwardingStrategy"); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 48 | |
| 49 | namespace ns3 { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 50 | namespace ndn { |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 52 | NS_OBJECT_ENSURE_REGISTERED (ForwardingStrategy); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 53 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 54 | TypeId ForwardingStrategy::GetTypeId (void) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 55 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 56 | static TypeId tid = TypeId ("ns3::ndn::ForwardingStrategy") |
Alexander Afanasyev | 4aac557 | 2012-08-09 10:49:55 -0700 | [diff] [blame] | 57 | .SetGroupName ("Ndn") |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 58 | .SetParent<Object> () |
| 59 | |
| 60 | //////////////////////////////////////////////////////////////////// |
| 61 | //////////////////////////////////////////////////////////////////// |
| 62 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 63 | .AddTraceSource ("OutInterests", "OutInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_outInterests)) |
| 64 | .AddTraceSource ("InInterests", "InInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_inInterests)) |
| 65 | .AddTraceSource ("DropInterests", "DropInterests", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropInterests)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 66 | |
| 67 | //////////////////////////////////////////////////////////////////// |
| 68 | //////////////////////////////////////////////////////////////////// |
| 69 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 70 | .AddTraceSource ("OutData", "OutData", MakeTraceSourceAccessor (&ForwardingStrategy::m_outData)) |
| 71 | .AddTraceSource ("InData", "InData", MakeTraceSourceAccessor (&ForwardingStrategy::m_inData)) |
| 72 | .AddTraceSource ("DropData", "DropData", MakeTraceSourceAccessor (&ForwardingStrategy::m_dropData)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 74 | .AddAttribute ("CacheUnsolicitedData", "Cache overheard data that have not been requested", |
| 75 | BooleanValue (false), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 76 | MakeBooleanAccessor (&ForwardingStrategy::m_cacheUnsolicitedData), |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 77 | MakeBooleanChecker ()) |
| 78 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 79 | .AddAttribute ("DetectRetransmissions", "If non-duplicate interest is received on the same face more than once, " |
| 80 | "it is considered a retransmission", |
| 81 | BooleanValue (true), |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 82 | MakeBooleanAccessor (&ForwardingStrategy::m_detectRetransmissions), |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 83 | MakeBooleanChecker ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 84 | ; |
| 85 | return tid; |
| 86 | } |
| 87 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 88 | ForwardingStrategy::ForwardingStrategy () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 89 | { |
| 90 | } |
| 91 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 92 | ForwardingStrategy::~ForwardingStrategy () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 93 | { |
| 94 | } |
| 95 | |
| 96 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 97 | ForwardingStrategy::NotifyNewAggregate () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 98 | { |
| 99 | if (m_pit == 0) |
| 100 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 101 | m_pit = GetObject<Pit> (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 102 | } |
| 103 | if (m_fib == 0) |
| 104 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 105 | m_fib = GetObject<Fib> (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 106 | } |
| 107 | if (m_contentStore == 0) |
| 108 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 109 | m_contentStore = GetObject<ContentStore> (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | Object::NotifyNewAggregate (); |
| 113 | } |
| 114 | |
| 115 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 116 | ForwardingStrategy::DoDispose () |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 117 | { |
| 118 | m_pit = 0; |
| 119 | m_contentStore = 0; |
| 120 | m_fib = 0; |
| 121 | |
| 122 | Object::DoDispose (); |
| 123 | } |
| 124 | |
| 125 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 126 | ForwardingStrategy::OnInterest (const Ptr<Face> &incomingFace, |
| 127 | Ptr<InterestHeader> &header, |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 128 | const Ptr<const Packet> &packet) |
| 129 | { |
| 130 | m_inInterests (header, incomingFace); |
| 131 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 132 | Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 133 | if (pitEntry == 0) |
| 134 | { |
| 135 | pitEntry = m_pit->Create (header); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 136 | if (pitEntry != 0) |
| 137 | { |
| 138 | DidCreatePitEntry (incomingFace, header, packet, pitEntry); |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | FailedToCreatePitEntry (incomingFace, header, packet); |
| 143 | return; |
| 144 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 147 | bool isDuplicated = true; |
| 148 | if (!pitEntry->IsNonceSeen (header->GetNonce ())) |
| 149 | { |
| 150 | pitEntry->AddSeenNonce (header->GetNonce ()); |
| 151 | isDuplicated = false; |
| 152 | } |
| 153 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 154 | if (isDuplicated) |
| 155 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 156 | DidReceiveDuplicateInterest (incomingFace, header, packet, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
| 160 | Ptr<Packet> contentObject; |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 161 | Ptr<const ContentObjectHeader> contentObjectHeader; // used for tracing |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 162 | Ptr<const Packet> payload; // used for tracing |
| 163 | boost::tie (contentObject, contentObjectHeader, payload) = m_contentStore->Lookup (header); |
| 164 | if (contentObject != 0) |
| 165 | { |
| 166 | NS_ASSERT (contentObjectHeader != 0); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 167 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 168 | pitEntry->AddIncoming (incomingFace/*, Seconds (1.0)*/); |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 169 | |
| 170 | // Do data plane performance measurements |
| 171 | WillSatisfyPendingInterest (0, pitEntry); |
| 172 | |
| 173 | // Actually satisfy pending interest |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 174 | SatisfyPendingInterest (0, contentObjectHeader, payload, contentObject, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 175 | return; |
| 176 | } |
| 177 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 178 | if (ShouldSuppressIncomingInterest (incomingFace, pitEntry)) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 179 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 180 | pitEntry->AddIncoming (incomingFace/*, header->GetInterestLifetime ()*/); |
| 181 | // update PIT entry lifetime |
| 182 | pitEntry->UpdateLifetime (header->GetInterestLifetime ()); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 183 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 184 | // Suppress this interest if we're still expecting data from some other face |
| 185 | NS_LOG_DEBUG ("Suppress interests"); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 186 | m_dropInterests (header, incomingFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 187 | return; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 188 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 189 | |
| 190 | PropagateInterest (incomingFace, header, packet, pitEntry); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 194 | ForwardingStrategy::OnData (const Ptr<Face> &incomingFace, |
| 195 | Ptr<ContentObjectHeader> &header, |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 196 | Ptr<Packet> &payload, |
| 197 | const Ptr<const Packet> &packet) |
| 198 | { |
| 199 | NS_LOG_FUNCTION (incomingFace << header->GetName () << payload << packet); |
| 200 | m_inData (header, payload, incomingFace); |
| 201 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 202 | // Lookup PIT entry |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 203 | Ptr<pit::Entry> pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 204 | if (pitEntry == 0) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 205 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 206 | DidReceiveUnsolicitedData (incomingFace, header, payload); |
| 207 | return; |
| 208 | } |
| 209 | else |
| 210 | { |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 211 | // Add or update entry in the content store |
| 212 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 213 | } |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 214 | |
| 215 | while (pitEntry != 0) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 216 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 217 | // Do data plane performance measurements |
| 218 | WillSatisfyPendingInterest (incomingFace, pitEntry); |
| 219 | |
| 220 | // Actually satisfy pending interest |
| 221 | SatisfyPendingInterest (incomingFace, header, payload, packet, pitEntry); |
| 222 | |
| 223 | // Lookup another PIT entry |
| 224 | pitEntry = m_pit->Lookup (*header); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
| 228 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 229 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 230 | ForwardingStrategy::DidReceiveDuplicateInterest (const Ptr<Face> &incomingFace, |
| 231 | Ptr<InterestHeader> &header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 232 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 233 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 234 | { |
Alexander Afanasyev | e288d8b | 2012-07-20 15:35:17 -0700 | [diff] [blame] | 235 | NS_LOG_FUNCTION (this << boost::cref (*incomingFace)); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 236 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 237 | // // |
| 238 | // !!!! IMPORTANT CHANGE !!!! Duplicate interests will create incoming face entry !!!! // |
| 239 | // // |
| 240 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 241 | pitEntry->AddIncoming (incomingFace); |
| 242 | m_dropInterests (header, incomingFace); |
| 243 | } |
| 244 | |
| 245 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 246 | ForwardingStrategy::DidExhaustForwardingOptions (const Ptr<Face> &incomingFace, |
| 247 | Ptr<InterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 248 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 249 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 250 | { |
Alexander Afanasyev | e288d8b | 2012-07-20 15:35:17 -0700 | [diff] [blame] | 251 | NS_LOG_FUNCTION (this << boost::cref (*incomingFace)); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 252 | m_dropInterests (header, incomingFace); |
| 253 | } |
| 254 | |
| 255 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 256 | ForwardingStrategy::FailedToCreatePitEntry (const Ptr<Face> &incomingFace, |
| 257 | Ptr<InterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 258 | const Ptr<const Packet> &packet) |
| 259 | { |
| 260 | NS_LOG_FUNCTION (this); |
| 261 | m_dropInterests (header, incomingFace); |
| 262 | } |
| 263 | |
| 264 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 265 | ForwardingStrategy::DidCreatePitEntry (const Ptr<Face> &incomingFace, |
| 266 | Ptr<InterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 267 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 268 | Ptr<pit::Entry> pitEntrypitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 269 | { |
| 270 | } |
| 271 | |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 272 | bool |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 273 | ForwardingStrategy::DetectRetransmittedInterest (const Ptr<Face> &incomingFace, |
| 274 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 275 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 276 | pit::Entry::in_iterator inFace = pitEntry->GetIncoming ().find (incomingFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 277 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 278 | bool isRetransmitted = false; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 279 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 280 | if (inFace != pitEntry->GetIncoming ().end ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 281 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 282 | // this is almost definitely a retransmission. But should we trust the user on that? |
| 283 | isRetransmitted = true; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 286 | return isRetransmitted; |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 290 | ForwardingStrategy::SatisfyPendingInterest (const Ptr<Face> &incomingFace, |
| 291 | Ptr<const ContentObjectHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 292 | Ptr<const Packet> payload, |
| 293 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 294 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 295 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 296 | if (incomingFace != 0) |
| 297 | pitEntry->RemoveIncoming (incomingFace); |
| 298 | |
| 299 | //satisfy all pending incoming Interests |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 300 | BOOST_FOREACH (const pit::IncomingFace &incoming, pitEntry->GetIncoming ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 301 | { |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 302 | bool ok = incoming.m_face->Send (packet->Copy ()); |
| 303 | if (ok) |
| 304 | { |
| 305 | m_outData (header, payload, incomingFace == 0, incoming.m_face); |
| 306 | DidSendOutData (incoming.m_face, header, payload, packet); |
| 307 | |
| 308 | NS_LOG_DEBUG ("Satisfy " << *incoming.m_face); |
| 309 | } |
| 310 | else |
| 311 | { |
| 312 | m_dropData (header, payload, incoming.m_face); |
| 313 | NS_LOG_DEBUG ("Cannot satisfy data to " << *incoming.m_face); |
| 314 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 315 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 316 | // successfull forwarded data trace |
| 317 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 318 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 319 | // All incoming interests are satisfied. Remove them |
| 320 | pitEntry->ClearIncoming (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 321 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 322 | // Remove all outgoing faces |
| 323 | pitEntry->ClearOutgoing (); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 324 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 325 | // Set pruning timout on PIT entry (instead of deleting the record) |
| 326 | m_pit->MarkErased (pitEntry); |
| 327 | } |
| 328 | |
| 329 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 330 | ForwardingStrategy::DidReceiveUnsolicitedData (const Ptr<Face> &incomingFace, |
| 331 | Ptr<const ContentObjectHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 332 | Ptr<const Packet> payload) |
| 333 | { |
| 334 | if (m_cacheUnsolicitedData) |
| 335 | { |
| 336 | // Optimistically add or update entry in the content store |
| 337 | m_contentStore->Add (header, payload); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 338 | } |
| 339 | else |
| 340 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 341 | // Drop data packet if PIT entry is not found |
| 342 | // (unsolicited data packets should not "poison" content store) |
| 343 | |
| 344 | //drop dulicated or not requested data packet |
| 345 | m_dropData (header, payload, incomingFace); |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 350 | ForwardingStrategy::WillSatisfyPendingInterest (const Ptr<Face> &incomingFace, |
| 351 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 352 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 353 | pit::Entry::out_iterator out = pitEntry->GetOutgoing ().find (incomingFace); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 354 | |
| 355 | // If we have sent interest for this data via this face, then update stats. |
| 356 | if (out != pitEntry->GetOutgoing ().end ()) |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 357 | { |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 358 | pitEntry->GetFibEntry ()->UpdateFaceRtt (incomingFace, Simulator::Now () - out->m_sendTime); |
| 359 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 360 | } |
| 361 | |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 362 | bool |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 363 | ForwardingStrategy::ShouldSuppressIncomingInterest (const Ptr<Face> &incomingFace, |
| 364 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 365 | { |
| 366 | bool isNew = pitEntry->GetIncoming ().size () == 0 && pitEntry->GetOutgoing ().size () == 0; |
| 367 | |
| 368 | if (isNew) return false; // never suppress new interests |
| 369 | |
| 370 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
| 371 | DetectRetransmittedInterest (incomingFace, pitEntry); |
| 372 | |
| 373 | if (pitEntry->GetOutgoing ().find (incomingFace) != pitEntry->GetOutgoing ().end ()) |
| 374 | { |
| 375 | NS_LOG_DEBUG ("Non duplicate interests from the face we have sent interest to. Don't suppress"); |
| 376 | // got a non-duplicate interest from the face we have sent interest to |
| 377 | // Probably, there is no point in waiting data from that face... Not sure yet |
| 378 | |
| 379 | // If we're expecting data from the interface we got the interest from ("producer" asks us for "his own" data) |
| 380 | // Mark interface YELLOW, but keep a small hope that data will come eventually. |
| 381 | |
| 382 | // ?? not sure if we need to do that ?? ... |
| 383 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 384 | // pitEntry->GetFibEntry ()->UpdateStatus (incomingFace, fib::FaceMetric::NDN_FIB_YELLOW); |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 385 | } |
| 386 | else |
| 387 | if (!isNew && !isRetransmitted) |
| 388 | { |
| 389 | return true; |
| 390 | } |
| 391 | |
| 392 | return false; |
| 393 | } |
| 394 | |
| 395 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 396 | ForwardingStrategy::PropagateInterest (const Ptr<Face> &incomingFace, |
| 397 | Ptr<InterestHeader> header, |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 398 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 399 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | 996b487 | 2012-07-17 17:07:56 -0700 | [diff] [blame] | 400 | { |
| 401 | bool isRetransmitted = m_detectRetransmissions && // a small guard |
| 402 | DetectRetransmittedInterest (incomingFace, pitEntry); |
| 403 | |
| 404 | pitEntry->AddIncoming (incomingFace/*, header->GetInterestLifetime ()*/); |
| 405 | /// @todo Make lifetime per incoming interface |
| 406 | pitEntry->UpdateLifetime (header->GetInterestLifetime ()); |
| 407 | |
| 408 | bool propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry); |
| 409 | |
| 410 | if (!propagated && isRetransmitted) //give another chance if retransmitted |
| 411 | { |
| 412 | // increase max number of allowed retransmissions |
| 413 | pitEntry->IncreaseAllowedRetxCount (); |
| 414 | |
| 415 | // try again |
| 416 | propagated = DoPropagateInterest (incomingFace, header, packet, pitEntry); |
| 417 | } |
| 418 | |
| 419 | // ForwardingStrategy will try its best to forward packet to at least one interface. |
| 420 | // If no interests was propagated, then there is not other option for forwarding or |
| 421 | // ForwardingStrategy failed to find it. |
| 422 | if (!propagated && pitEntry->GetOutgoing ().size () == 0) |
| 423 | { |
| 424 | DidExhaustForwardingOptions (incomingFace, header, packet, pitEntry); |
| 425 | } |
| 426 | } |
Alexander Afanasyev | e3d126f | 2012-07-16 17:07:31 -0700 | [diff] [blame] | 427 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 428 | bool |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 429 | ForwardingStrategy::WillSendOutInterest (const Ptr<Face> &outgoingFace, |
| 430 | Ptr<InterestHeader> header, |
| 431 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 432 | { |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 433 | pit::Entry::out_iterator outgoing = |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 434 | pitEntry->GetOutgoing ().find (outgoingFace); |
| 435 | |
| 436 | if (outgoing != pitEntry->GetOutgoing ().end () && |
| 437 | outgoing->m_retxCount >= pitEntry->GetMaxRetxCount ()) |
| 438 | { |
| 439 | NS_LOG_ERROR (outgoing->m_retxCount << " >= " << pitEntry->GetMaxRetxCount ()); |
| 440 | return false; // already forwarded before during this retransmission cycle |
| 441 | } |
| 442 | |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 443 | pitEntry->AddOutgoing (outgoingFace); |
| 444 | return true; |
| 445 | } |
| 446 | |
| 447 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 448 | ForwardingStrategy::DidSendOutInterest (const Ptr<Face> &outgoingFace, |
| 449 | Ptr<InterestHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 450 | const Ptr<const Packet> &packet, |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 451 | Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 452 | { |
| 453 | m_outInterests (header, outgoingFace); |
| 454 | } |
| 455 | |
| 456 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 457 | ForwardingStrategy::DidSendOutData (const Ptr<Face> &face, |
| 458 | Ptr<const ContentObjectHeader> header, |
Alexander Afanasyev | 1c0248b | 2012-07-24 15:59:50 -0700 | [diff] [blame] | 459 | Ptr<const Packet> payload, |
| 460 | const Ptr<const Packet> &packet) |
| 461 | { |
| 462 | } |
| 463 | |
| 464 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 465 | ForwardingStrategy::WillErasePendingInterest (Ptr<pit::Entry> pitEntry) |
Alexander Afanasyev | f249a19 | 2012-07-18 16:52:51 -0700 | [diff] [blame] | 466 | { |
| 467 | // do nothing for now. may be need to do some logging |
| 468 | } |
| 469 | |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 470 | |
| 471 | void |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 472 | ForwardingStrategy::RemoveFace (Ptr<Face> face) |
Alexander Afanasyev | 33364b6 | 2012-07-26 17:53:56 -0700 | [diff] [blame] | 473 | { |
| 474 | // do nothing here |
| 475 | } |
| 476 | |
Alexander Afanasyev | 2b4c947 | 2012-08-09 15:00:38 -0700 | [diff] [blame] | 477 | } // namespace ndn |
| 478 | } // namespace ns3 |